为什么 linkButton 不更改其 commandArgument - 即使在创建新实例并重新分配新值之后也是如此?
所以我有一个名为 linkButton 的 LinkButton。
protected LinkButton linkButton;
在获取指定目录的每个目录的循环中,我有以下内容:
linkButton = new LinkButton();
linkButton.Text = DirInf.Name;
linkButton.CommandArgument = DirInf.FullName;
linkButton.Command += new CommandEventHandler(linkButton_Command);
其中 DirInf 的类型为 DirectoryInfo。
现在,当我将:
Response.Redirect("filebrowser.aspx?dir=" + linkButton.CommandArgument);
linkButton = new LinkButton();
在函数 linkButton_Command 中放置时,linkButton.CommandArgument 似乎始终是“C:\Windows”,这恰好是分配的最后一个值 linkButton.CommandArgument。
但我创建了它的一个新实例 - 但该值仍然保留......
我很困惑......
So I have a LinkButton called linkButton.
protected LinkButton linkButton;
and inside a loop which gets every directory of a specified directory, I have this:
linkButton = new LinkButton();
linkButton.Text = DirInf.Name;
linkButton.CommandArgument = DirInf.FullName;
linkButton.Command += new CommandEventHandler(linkButton_Command);
Where DirInf is of type DirectoryInfo.
Now when I put:
Response.Redirect("filebrowser.aspx?dir=" + linkButton.CommandArgument);
linkButton = new LinkButton();
inside the function linkButton_Command, linkButton.CommandArgument seems to always be "C:\Windows," which so happens to be the last value linkButton.CommandArgument was assigned.
But I created a new instance of it - but the value still retains...
I'm quite puzzled...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Response.Redirect
将抛出ThreadAbortException
,因此您的分配实际上从未发生。我很好奇您何时再次测试该值,考虑到 ASP.NET 状态的工作方式...是在下一个请求上吗?我承认对你实际上在做什么有点困惑。您能否提供一个简短但完整的示例(页面+代码隐藏)来演示该问题?
Response.Redirect
will throw aThreadAbortException
, so your assignment is never actually taking place. I'm curious as to when you were testing the value again as well, given the way that ASP.NET state works... was it on the next request?I admit to being somewhat confused as to what you're actually doing. Could you provide a short but complete example (page + codebehind) which demonstrates the problem?