简体   繁体   中英

Asp .net Linkbutton child controls dissapears on postback

I have an asp .net hyperlink control declared like this:

  <li runat="server" id="liveChatCtrl" Visible="false"><asp:LinkButton runat="server" ID="hlnkLiveChat" CausesValidation="false" OnClick="hlnkLiveChat_Click">Live Chat Support <i class="icon icon_next_03 fr"></i><i runat="server" id="iconChat" class="icon_chat_online"></i></asp:LinkButton></li>

My problem is that the contents of the linkbutton disappears on postback. Any ideas why this is happening?

On load I execute the following code on the linkbutton or it's children:

                string absoluteURL = UtilManager.Settings.Item(Utils.BrandID, "URL:absoluteURL");
            string chatLink = "StartChat.aspx";
            if (HttpContext.Current.User.Identity.IsAuthenticated)
                chatLink = "LiveChat.aspx";//~/
            //else
            //    chatLink = "SalesChat.aspx";
            string link = absoluteURL + chatLink;
            hlnkLiveChat.Attributes["onclick"] = string.Format("javascript:window.open( '{0}', 'chat', 'status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=505,width=420,left=30,top=30');", link);//"openPopup('" + link + "','chat'); return false;";            
            liveChatCtrl.Visible = true;

A guess...

I believe you may have the code in your Page_Load (or Init ) inside an if(!IsPostBack)

If this is the case, move it outside of this if statement as you need it to run as your default visible for your liveChatCtrl is false

Either that or re-code a little so that your default visible is true and you run a check on postback to hide it if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM