Run Modal Code Behind ASP.NET?

Asked

Viewed 176 times

-3

I’m trying to run a modal through ASP.NET and I got it;

Using the Script

  <div id="mymodals" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">
                        <asp:Label Text="" ID="lbl_errortitulo" runat="server" /></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <asp:Label Text="" ID="lbl_errormsg" runat="server" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Entendi</button>
                </div>
            </div>
        </div>
    </div>
    <div>
        <div>
            <p class="btn btn-primary" id="btn_execute" onclick="Mensagem()" >Executar</p>
        </div>
    </div>

    <script type="text/javascript">
        function Mensagem() {
            $('#mymodals').modal({ show: true });
        }          
    </script>

However, if I put it on an Asp:Button I think Postback will make you "bugger off"...

The doubt is, needed to run this modal by code-Behind when it fell into the "catch", using;

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), 
                      "mymodals", 
                      "Mensagem();", 
                      true
);

Only, it does not perform, I believe it is the postback!?

  • The data are fixed?

  • As so fixed?

  • Show Modal ??? and ???? because if it’s Javascript you don’t need to switch to Backend

  • So I wanted you to call Modal in case I fell in the Try block catch

  • There’s nothing in your question that shows try catch!

  • The doubt is, needed to run this modal by code-Behind when it fell into the "catch", using;

  • Your doubt is not clear, there is no catch, there is no code-Behind in the question, there is only one page code aspx(excerpt) and a function in javascript ... ie, rephrase your question

Show 2 more comments

2 answers

0


Page.ClientScript.RegisterStartupScript(GetType(), key: "script", script: "<script>$('#mymodals').modal('show');</script> ", addScriptTags: false);
  • Exactly what does this code do and how could it be the solution to the question? (Don’t reply with a comment to me, edit and improve your response)

0

I got it this way:

 <asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel runat="server">
                <ContentTemplate>
                    <asp:Button Text="Abrir Modal" ID="btn_button" runat="server" OnClick="btn_button_Click1" />
                </ContentTemplate>
            </asp:UpdatePanel>
  • I do not know the purpose, lack information, you did not solve the problem maybe ended up creating another, if you know what is Updatepanel ? so ... beware of solutions so I think I don’t even need it, but, lack context in your question.

  • So, I had to run a Modal if the Try block entered Catch (when it generated an error) just to show the user that it was an error, but I had to do it from Code-Behind, only I simply didn’t run it using Scriptmanager.Registerclientscriptblock(this, this.Gettype(), "Modal", "Message()", true);

  • What is this "other problem" that I may have created?

  • So you put this in the Updatepanel which is Ajax summarizing ... but, need? something else in no time has Try catch on your question, where is it, on the programming part ?

  • Yes, basically Asp:Button would perform a registration function inside a Trycatch block, and if it fell in Catch, I would call Modal through Javascript stating which error it gave, understand? but I was unable to execute the Javascript Function in Code-Behind, and that way I was able to

Browser other questions tagged

You are not signed in. Login or sign up in order to post.