Add a "class" to a body without postback using ajax

0

I am using ajax and I have a problem! when I use the ModalPopupExtender it shows what I want but I can not add a class to a tag, specifically to the "body" tag I have the following code

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body id="css_body" runat="server">
  <form id="form1" runat="server">
  
    <ajaxToolkit:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnInicial" CancelControlID="btnClose" BackgroundCssClass="modal-backdrop fade in"></ajaxToolkit:ModalPopupExtender>
    
    <asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    
      <ContentTemplate>
        <asp:Button ID="Button2" runat="server" Text="Show Modal Popup" OnClick="btnShow_Click" />
      </ContentTemplate>
    </asp:UpdatePanel>

    <asp:Button ID="btnInicial" runat="server" Text="Button" style="display:none" />

    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none">
      <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>

          <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </ContentTemplate>
      </asp:UpdatePanel>

      <asp:Button ID="btnClose" runat="server" Text="Close" />
    </asp:Panel>


  </form>
</body>

</html>

when I click on the buton1 it shows me the label until it changes the "Text" property without postback but the label I want to change does not change I have the following code on the server side

protected void btnShow_Click(object sender, EventArgs e) 
{ 
Page.ClientScript.RegisterStartupScript(this.GetType(), "style", "document.getElementById('css_body').classList.add('modal-open');", true);

Label1.Text = "resultado";

mp1.Show();
}

How could I fix it?

    
asked by aldair guzman bolaños 18.06.2018 в 11:18
source

1 answer

0

You should use the ScriptManager instead of Page.ClientScript :

ScriptManager.RegisterStartupScript(
    this,
    GetType(),
    "style", 
    "document.getElementById('css_body').classList.add('modal-open');", 
    true);
    
answered by 18.06.2018 / 13:03
source