Rahul Raman
Rahul Raman

Reputation: 13

Display Bootstrap ModalPopup on Click on ASP Button without using Modalpopupextender

I am trying to call a javascript function on Click event of ASP Button and from that function I am trying to click the html button that will invoke the Modal Pop.

Status: I am able to file the html button's click event and run an alertbox in it but not ModalPopup. I am also able to open the ModalPopup by directly clicking the HTML Code.

Code: //Code

protected void Button1_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    RepeaterItem ri = (RepeaterItem)btn.Parent;
    Label id = (Label)ri.FindControl("payid");
    Add_Account_Head_1.headid_property = id.Text;

    update1.Update();

    string script = "showpop();";
    ScriptManager.RegisterStartupScript(this, GetType(),
                          "ServerControlScript", script, true);

}

In Body Section

 $("#btn1").click(function () {
         //     alert('This has been clicked');
        $("#myModal").modal('show');


    });

In the Head Section

     function showpop() {

            var button = document.getElementById('btn1');
            button.click();
        };

Upvotes: 1

Views: 310

Answers (1)

Nisarg Shah
Nisarg Shah

Reputation: 14541

You can do something like this to invoke the modal.show directly from the server side. But make sure that #myModal is the correct selector. You can verify the ID from the dev tools.

protected void Button1_Click(object sender, EventArgs e)
{
    Button btn = (Button)sender;
    RepeaterItem ri = (RepeaterItem)btn.Parent;
    Label id = (Label)ri.FindControl("payid");
    Add_Account_Head_1.headid_property = id.Text;

    update1.Update();

    string script = "showpop();";
    ScriptManager.RegisterStartupScript(this, GetType(),
                          "ServerControlScript", "$('#myModal').modal('show');", true);

}

Upvotes: 1

Related Questions