Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am trying to load modal pop up extender from code behind VB. I have tried using Javascript but not sure if my syntax is correct. I tried using javascript to call launchModal() function in front but it doesn't seem to be calling the function. Ideally, The function will search for the modal ID = mp1 and load it. But it doesn't work. Please help, thank you.
<pre><div class="box-footer">
                        <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" class="btn btn-default" Width="100px" />
                        <asp:Button ID="Client" runat="server" Text="Client Side" class="btn btn-default" />
                    </div>
                    <!-- /.box-footer -->
                </div>
            </div>
            <!-- /.box -->
            <!-- general form elements disabled -->
        </div>
    </div>
    <!-- ModalPopupExtender -->
    <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="Client"
        CancelControlID="btnClose" BackgroundCssClass="modal-background">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="Panel1" runat="server" CssClass="modal-popup" align="center" Style="display: none">
        <br />
        <br />
        Group Code cannot be empty<br />
        <asp:Button ID="btnClose" runat="server" Text="Close" />
    </asp:Panel>
    <!-- ModalPopupExtender -->
    <script type="text/javascript">
        function launchModal(){
            var id = $find("mp1");
            if (id)
                id.show();
            else
                alert("Not found");
        }

        //var launch = false;
        //function launchModal() {
        //    launch = true;
        //}
        //function pageLoad() {
        //    if (launch) {
        //        $find("mp1").show();
        //    }
        //}
    </script>
</asp:Content>





My Code Behind

Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If txtGrpCode.Text = "" Then
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "window-script", "launchModal()", True)
            Response.Redirect("frmFm01det.aspx")
        End If


What I have tried:

I have tried using javascript(not sure if my syntax is correct) to call the function infront but it doesn't work at all. I don't even know how to debug.
Posted
Updated 4-Jul-17 2:48am

1 solution

Quote:
Page.ClientScript.RegisterStartupScript(...)
Response.Redirect("frmFm01det.aspx")

RegisterStartupScript tells the page to output the specified script block when the page is rendered.

Response.Redirect then tells the page to throw everything away, and send an empty response telling the browser to load a different page.

If you want the script to run, you need to remove the redirection.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900