C# MultiView SetActiveView by ID 无法正常工作
我目前正在尝试找出我的代码有什么问题:
不起作用 工作
if(...){
...
}else{
someVariableAsString = "myValue123";
MultiView1.SetActiveView(My3thView_ID_In_MultiViewControl);
}
..
if(...){
...
}else{
//someVariableAsString = "myValue123";
MultiView1.SetActiveView(My3thView_ID_In_MultiViewControl);
}
为什么以及对此有什么解决方案吗?
I'm currently trying to figure out what's wrong with my code:
Doesn't work
if(...){
...
}else{
someVariableAsString = "myValue123";
MultiView1.SetActiveView(My3thView_ID_In_MultiViewControl);
}
Works
if(...){
...
}else{
//someVariableAsString = "myValue123";
MultiView1.SetActiveView(My3thView_ID_In_MultiViewControl);
}
.. why and any solutions for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您尝试对 INIT 而不是负载进行操作,因此数据尚未附加到服务器。
您应该会发现 ASP.NET 中 Web 请求生命周期的回顾很有用: MSDN ASP.NET 页面生命周期
以下是相关摘录:
将您尝试执行的代码移至页面加载处理程序中(或之后)(请记住测试 IsPostBack),然后查看是否没有得到您想要的结果。
尝试新事物:
尝试将您的不起作用更改为:
Because you are attempting to act on the INIT rather than the load, the data has not yet been attached at the server.
You should find this review of the life cycle of a web request in ASP.NET useful: MSDN ASP.NET Page Life Cycle
Here is the relevant extract:
Move the code you are trying to execute into (or after) the page load handler (remember to test for IsPostBack) and see if that doesn't get what you want.
Something New to try:
try changing your doesn't work to:
听起来 someVariableAsString 可能会引发异常,导致代码无法到达下一行。检查你的变量类型。
It sounds like someVariableAsString is possibly throwing an exception to cause the code not to reach the next line. Check your variable type.
我能够为我的案例找到解决方案:
我将
someVariableAsString
更改为属性作为视图。创建了一个 Gobal.asax 会话变量,现在我得到了正确的结果(稍后加载一页)。 :-)
但就我而言这就可以了。
问题解决了。
I was able to get a solution to my case:
I changed
someVariableAsString
to a Property as View.Created a session variable to Gobal.asax and now I get correct result (one page load later). :-)
but in my case this will do.
Problem solved.