Control Lightbox (Modal) From Code-Behind Of Asp.Net

吃可爱长大的小学妹 提交于 2019-12-11 15:16:00

问题


Before meeting with Ajax and Jquery, in my projects I had a function like below.

Public Sub Raise_Alarm(ByVal p_Page As Page, ByVal p_Message As String, Optional ByVal p_IsError As Boolean = True)

strScript = "<script language= ""javascript""> alert('" & p_Message.Replace("'", "") & "')</script>"
    Dim t As Type = p_Page.GetType()
    p_Page.ClientScript.RegisterStartupScript(t, "alert", strScript)
    Dim mylabel As Label

end sub

For now I want to a function instead of function above, which show message as a lightbox (modal box).

How can I do it?


回答1:


If you want to use jqModal as suggested by cxfx above (+1;), this should work:

strScript = "$('<div>" & p_Message.Replace("'", "\'") & "</div>').jqm();";
ClientScriptManager.RegisterStartupScript(p_Page.GetType(), "alert", strScript, true);



回答2:


Try one of the excellent jQuery plugins for displaying modal windows such as jqModal. The docs explain how to configure and launch your modal window, and include some great examples.




回答3:


If you are using "thickbox" it can just display a noraml aspx page in a modal window. You can then use code behind as normal.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

<link href="/themes/ui.all.css" rel="stylesheet" type="text/css" />       
<link runat="server" href="/styles/thickbox.css" rel="stylesheet" type="text/css" />       
<!-- jQuery -->
<script type="text/javascript" src="/scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="/scripts/ui.core.js"></script>
<script type="text/javascript" src="/scripts/thickbox.js"></script>      

</head>
<body>
       <a class="thickbox" href="mylink.aspx?KeepThis=true&TB_iframe=true&height=300&width=850">modal thick box link</a>
</body>
</html>

Hope this helps.



来源:https://stackoverflow.com/questions/625326/control-lightbox-modal-from-code-behind-of-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!