尝试在 PageLoad 中的 UpdatePanel 内设置视图
我在使用 UpdatePanel 和 MultiView 的组合时遇到问题。
我的顶层有一个 UpdatePanel,里面有一堆图像按钮 - 它们的单击事件设置多视图上的视图,每个视图内部都有一个带有我的绑定的 UpdatePanel。
一切都很好 - 但我试图通过查询字符串设置视图,这样我就可以将用户发送到特定的视图。
当我尝试从 PageLoad 设置视图时 - 它说“对象不存在”。 所以我想我应该在 Page_LoadComplete 中尝试一下,效果很好 - 但随后我的图像按钮无法像原来那样切换视图。
我还缺什么啊! 谢谢!
void Page_LoadComplete()
{
tabSelect= Request.QueryString["tab"];
if (tabSelect.Contains("Community"))
{
MultiView1.SetActiveView(Community);
btnCommunity.ImageUrl = "images/tabCommunity_on.png";
}
}
<asp:ScriptManager id="ScriptManager1" runat="server"/>
<asp:UpdatePanel id="UpdatePanel1" childrenastriggers="true" updatemode="Always" runat="server">
<ContentTemplate>
<asp:ImageButton id="btnCommunity" onclick="" runat="server">
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="Community" runat="server">
<asp:UpdatePanel id="UpdatePanel1" childrenastriggers="true" updatemode="Always" runat="server">
//data controls in here
</asp:UpdatePanel>
</asp:View>
<asp:View id="tabFriends" runat="server">
<asp:UpdatePanel id="UpdatePanel2" childrenastriggers="true" updatemode="Always" runat="server">
//data controls in here
</asp:UpdatePanel>
</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>
I'm having trouble with a combination of an UpdatePanel and MultiView.
I have an UpdatePanel at my top level, inside I have a bunch of imagebuttons - their click events set the view on the Multiview, and each View has an UpdatePanel inside of it with my binding.
Everything works great - but I am trying to set the View via the Querystring, so I can send a user to a particular view.
When I try and set the View from PageLoad - it says 'object does not exist'. So I figured I'd try it in Page_LoadComplete, which works great - but then my imagebuttons don't work to switch the view like they originally did.
What am I missing! Thanks!
void Page_LoadComplete()
{
tabSelect= Request.QueryString["tab"];
if (tabSelect.Contains("Community"))
{
MultiView1.SetActiveView(Community);
btnCommunity.ImageUrl = "images/tabCommunity_on.png";
}
}
<asp:ScriptManager id="ScriptManager1" runat="server"/>
<asp:UpdatePanel id="UpdatePanel1" childrenastriggers="true" updatemode="Always" runat="server">
<ContentTemplate>
<asp:ImageButton id="btnCommunity" onclick="" runat="server">
<asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
<asp:View ID="Community" runat="server">
<asp:UpdatePanel id="UpdatePanel1" childrenastriggers="true" updatemode="Always" runat="server">
//data controls in here
</asp:UpdatePanel>
</asp:View>
<asp:View id="tabFriends" runat="server">
<asp:UpdatePanel id="UpdatePanel2" childrenastriggers="true" updatemode="Always" runat="server">
//data controls in here
</asp:UpdatePanel>
</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:在进一步详细检查您的代码后,我相信已经解决了问题。
我对代码做了以下调整:
如果未传递查询字符串,请将
tabSelect
设置为空字符串,从而避免下一行出现空对象引用异常。将 ImageUrl 路径设置为包含 ~(对于 root)。
请尝试以下代码:
UPDATE: After reviewing your code in further detail, I believe figured out the problem.
I made the following adjustments to the code:
If the querystring is not passed, set
tabSelect
to empty string and thus avoiding a null object reference exception on the next line.Set the ImageUrl path to include ~ (for root).
Please try the code below: