【问题标题】:ASP.NET: Show jQuery dialog after button clickASP.NET:单击按钮后显示 jQuery 对话框
【发布时间】:2013-04-10 04:24:48
【问题描述】:

在我的 ASP.NET 页面上,我有一个按钮。单击服务器端后,应该生成一个 div,代表 jQuery 对话框和相关 JavaScript 块的内容。但是单击按钮后,页面上既不包含 div 也不包含 JavaScript。点击注册控件和脚本是否为时已晚或为什么不起作用?

'create JavaScript block
Dim strClientScript As String = String.Empty
Dim strMessageControlId As String = "jQueryDialog" & Me.MyContainer.Controls.Count
strClientScript &= "$(function(){" & NewLine
strClientScript &= "    $(""#" & strMessageControlId & """).dialog({" & NewLine
strClientScript &= "        bgiframe:true, " & NewLine
strClientScript &= "        autoOpen:true, " & NewLine
strClientScript &= "        modal:true, " & NewLine
strClientScript &= "        closeOnEscape:false, " & NewLine
strClientScript &= "        width:600, " & NewLine
strClientScript &= "        height:450 " & NewLine
strClientScript &= "    });" & NewLine
strClientScript &= "});"

'create div for the jQuery Dialog
Dim strHtml As String = String.Empty
strHtml &= "<div id=""" & strMessageControlId & """ title=""My title"">" & NewLine
strHtml &= strMessage & NewLine
strHtml &= "</div>"

'add the HTML to the page
Me.MyContainer.Controls.Add(New LiteralControl(strHtml))

'register the Javascript
Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "Key." & strMessageControlId, strClientScript, True)

【问题讨论】:

    标签: jquery asp.net vb.net serverside-javascript registerclientscriptblock


    【解决方案1】:

    我以前做过。它不适合你,但值得一试。 在页面上创建 div 元素并在其上放置“display:none”。在客户端使用 jquery,为您的按钮添加一个单击事件。在 click 事件中附加数据或编写一个函数来填充并显示 div 或显示您想要在其中显示的内容。真的没有理由做这个服务器端。在您的 click jquery click 事件中,您可以将要添加到 div、样式等的所有属性链接起来,以使其看起来像您想要的那样。如果您需要更好的解释,我会尝试找到一个示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多