简体   繁体   中英

ASP.NET: Show jQuery dialog after button click

On my ASP.NET page I have a button. After click on the server side should be generate a div which represent the content for a jQuery dialog and the related JavaScript block. But neither the div nor the JavaScript are contained on the page after the button click. Is it too late to register controls and scripts at the click or why doesn't work?

'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)

I have done this before. It mat not work for you but it is worth a try. Create the div element on your page and put a "display:none" on it. On the client side using jquery, Add a click event for your button. Inside the click event append the data or write a function to filland show the div or show what you want to show inside of it. There's really no reason to do this sever side. Inside your click jquery click event you can chain all the attributes you want to add to your div, style's and such to make it look the way you want. If you need a better explanation I will try and find an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM