如何从ASP.NET VB背后的代码做modalpopupextender

问题描述:

您好我正在尝试从VB后面的代码加载模式弹出扩展程序。我尝试过使用Javascript,但不确定我的语法是否正确。我尝试使用javascript在前面调用launchModal()函数,但它似乎没有调用该函数。理想情况下,该函数将搜索模态ID = mp1并加载它。但它不起作用。请帮助,谢谢。

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





我尝试过:



我尝试使用javascript(不确定我的语法是否正确)来调用infront函数,但它根本不起作用。我甚至不知道如何调试。



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.

find(mp1);
if(id)
id.show();
else
alert(Not found);
}

// var launch = false;
//函数launchModal(){
// launch = true;
//}
// function pageLoad(){
// if(launch){
//
find("mp1"); if (id) id.show(); else alert("Not found"); } //var launch = false; //function launchModal() { // launch = true; //} //function pageLoad() { // if (launch) { //


find(mp1 )。节目();
//}
//}
< / script>
< / asp:Content>
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





我尝试过:



我尝试使用javascript(不确定我的语法是否正确)来调用infront函数,但它根本不起作用。我甚至不知道如何调试。



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.


Quote:

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



RegisterStartupScript 告诉页面在呈现页面时输出指定的脚本块。



Response.Redirect 然后告诉页面扔掉所有东西,并发送一个空响应告诉浏览器加载一个不同的页面。



如果你想让脚本运行,你需要删除重定向。


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.