尝试在 PageLoad 中的 UpdatePanel 内设置视图

发布于 2024-07-18 15:55:02 字数 1600 浏览 4 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄居者 2024-07-25 15:55:02

更新:在进一步详细检查您的代码后,我相信已经解决了问题。

我对代码做了以下调整:

  1. 如果未传递查询字符串,请将 tabSelect 设置为空字符串,从而避免下一行出现空对象引用异常。

  2. 将 ImageUrl 路径设置为包含 ~(对于 root)。

请尝试以下代码:

void Page_LoadComplete()
{
    string tabSelect = Request.QueryString["tab"] ?? string.Empty;

    if (tabSelect.Contains("Community"))
    {
        MultiView1.SetActiveView(Community);
        btnCommunity.ImageUrl = "~/images/tabCommunity_on.png";
    }
}

UPDATE: After reviewing your code in further detail, I believe figured out the problem.

I made the following adjustments to the code:

  1. If the querystring is not passed, set tabSelect to empty string and thus avoiding a null object reference exception on the next line.

  2. Set the ImageUrl path to include ~ (for root).

Please try the code below:

void Page_LoadComplete()
{
    string tabSelect = Request.QueryString["tab"] ?? string.Empty;

    if (tabSelect.Contains("Community"))
    {
        MultiView1.SetActiveView(Community);
        btnCommunity.ImageUrl = "~/images/tabCommunity_on.png";
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文