Search code examples
c#asp.netvariablesmodalpopupextender

How to add C# variables to html modal


In my ASP.Net app, I have a button that launches a modal. The onClick event fires the C# behind code that launches a modal. I am then calling a data table and populating string variables with values from the data table:

   protected void uxTicketHistoryButton_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "key", "launchModal();", true);

        DataTable ticketHist = _dtMgr.GetContactInfoByName(uxContactDropdownList.SelectedValue);
        string rName = ticketHist.Rows[0]["RequestorName"].ToString();
        string rPhone = ticketHist.Rows[0]["RequestorPhone"].ToString();
        string rPhoneExt = ticketHist.Rows[0]["RequestorPhoneExt"].ToString();
        string rEmail = ticketHist.Rows[0]["RequestorEmail"].ToString(); ;
        string rState = ticketHist.Rows[0]["RequestorState"].ToString();
        string rOrg = ticketHist.Rows[0]["RequestorOrg"].ToString();
    }

What I want to do now is add those variable values to my modal inside the panel.

<asp:Button ID="uxTicketHistoryButton" runat="server" Text="Show Ticket History"  style="color: blue;" OnClick="uxTicketHistoryButton_Click"/>&nbsp;

<!-- ModalPopupExtender-->
    <ajaxToolkit:ModalPopupExtender ID="uxTicketHistoryModal" runat="server" PopupControlID="Panel1" TargetControlID="uxTicketHistoryButton"CancelControlID="btnClose" BackgroundCssClass="modalBackground">
    </ajaxToolkit:ModalPopupExtender>
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">                                
        **** Add variable values here ****
        <asp:Button ID="btnClose" runat="server" Text="Close" />
    </asp:Panel> 

How do I add the variables from my .cs file to the modal panel in my .aspx file so that it shows up like this (values in the { } )? enter image description here

UPDATE This issue seems to be related to the modal interfering with the _Click event function of my button. I have posted an additional question to resolve this problem first. Then, I believe one of the solutions below may work. Thanks everybody!


Solution

  • Webform:

       <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">                                
                Name: <asp:Literal ID="Name" runat="server" /><br>
                Organization: <asp:Literal ID="Organization" runat="server" /><br>
                etc....
                <asp:Button ID="btnClose" runat="server" Text="Close" />
        </asp:Panel>
    

    Codebehind:

    Name.Text = ticketHist.Rows[0]["RequestorName"].ToString(); 
    Organization.Text = ticketHist.Rows[0]["RequestorOrg"].ToString()