Assigning dynamic Text to Label and Display in Ajax ModalPopupExtender in ASP.Net

Last Reply on Apr 11, 2017 12:01 PM By ti2016

Posted on Apr 11, 2017 08:57 AM

I am using ajax modal popup to display the type of error when a user submits a request. The code behind (vb) evaluates if all conditions are met and if not, a message is displayed to the user notifying what is missing. I can't seem to figure out how to set up the message body from the code behind before displaying the modal dialog. This is the code for the dialog I modified from a post in ASP Snippets:

<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mpe" runat="server"
 PopupControlID="pnlPopup" TargetControlID="lnkDummy" BackgroundCssClass="modalBackground" CancelControlID = "btnHide" Drag="true">
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
   <div class="ModalHeader">
       Message Title
    <div id="msgBody" class="ModalBody" runat="server">
       Message Body
    <br /><br />
       <asp:Button ID="btnHide" runat="server" Text="OK"/>

Then in the code behind I try to set up the div text and open the modal dialog:

msgBody.InnerHtml = strMessage

However, nothing shows in the body of the message. I tried adding a text box, label in the message body <div> and assign a value to these elements with no success.

You are viewing reply posted by: ti2016 on Apr 11, 2017 12:01 PM.
Posted on Apr 11, 2017 12:01 PM


I was able to find a solution using the article below:


I needed to move the html within the Update Panel and create a label in  msgBody div which I assign the message to:

Label1.Text = strMessage