On my default page I have a button that when clicked opens a dialog. When I open then close the dialog in that page then click a button and go to another page then click the browser's back button the dialog is opened again. When I click the back button I
want the dialog closed until that button is clicked again. I've been trying to find a solution and nothing has worked. The solutions I've found either don't fix the problem or have made the dialog not show at all.
I am calling the dialog in my code behind.
Private Sub runjQueryCode(ByVal jsCodetoRun As String)
Dim requestSM As ScriptManager = ScriptManager.GetCurrent(Me)
If requestSM IsNot Nothing AndAlso requestSM.IsInAsyncPostBack Then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), True)
Else
ClientScript.RegisterClientScriptBlock(GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), True)
End If
End Sub
Private Function getjQueryCode(ByVal jsCodetoRun As String) As String
Dim sb As New StringBuilder()
sb.AppendLine("$(document).ready(function() {")
sb.AppendLine(jsCodetoRun)
sb.AppendLine(" });")
Return sb.ToString()
End Function
Protected Sub chpassword_Click(ByVal sender As Object, ByVal e As EventArgs) Handles chpassword.Click
runjQueryCode("$('#dialog3').dialog({ autoOpen: false, show: 'blind', hide: 'clip', width: 550, height: 350, modal: true })")
runjQueryCode("$('#dialog3').parent().appendTo('form')")
runjQueryCode("$('#dialog3').dialog('open')")
End Sub
Now only the title of the dialog opens, the content inside the dialog is not visible. I tried adding ("open") somehwere in your code which gave a javascript error, when I hit continue or ignore the entire dialog was displaying properly.
Thanks to your help, the good news is when I went to a new page and clicked back the dialog was not open! Now I just need the entire dialog to display..
nellylou
Member
3 Points
11 Posts
Keep jQuery dialog closed on back button
Feb 27, 2013 06:42 PM|LINK
On my default page I have a button that when clicked opens a dialog. When I open then close the dialog in that page then click a button and go to another page then click the browser's back button the dialog is opened again. When I click the back button I want the dialog closed until that button is clicked again. I've been trying to find a solution and nothing has worked. The solutions I've found either don't fix the problem or have made the dialog not show at all.
I am calling the dialog in my code behind.
Private Sub runjQueryCode(ByVal jsCodetoRun As String) Dim requestSM As ScriptManager = ScriptManager.GetCurrent(Me) If requestSM IsNot Nothing AndAlso requestSM.IsInAsyncPostBack Then ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), True) Else ClientScript.RegisterClientScriptBlock(GetType(Page), Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), True) End If End Sub Private Function getjQueryCode(ByVal jsCodetoRun As String) As String Dim sb As New StringBuilder() sb.AppendLine("$(document).ready(function() {") sb.AppendLine(jsCodetoRun) sb.AppendLine(" });") Return sb.ToString() End Function Protected Sub chpassword_Click(ByVal sender As Object, ByVal e As EventArgs) Handles chpassword.Click runjQueryCode("$('#dialog3').dialog({ autoOpen: false, show: 'blind', hide: 'clip', width: 550, height: 350, modal: true })") runjQueryCode("$('#dialog3').parent().appendTo('form')") runjQueryCode("$('#dialog3').dialog('open')") End SubThis is the button's code.
<asp:Button ID="chpassword" runat="server" CommandName="chpassword" href="#" Text="Forgot Password?" onclick="chpassword_Click" UseSubmitBehavior="False" />This is the div for the dialog.
<asp:ScriptManager ID="ScriptManager1" runat="server"/> <div id="dialog3" class="pop" runat="server" style="display:none"> //form code </div>I don't know what I'm missing!
rajendraram
Participant
812 Points
258 Posts
Re: Keep jQuery dialog closed on back button
Feb 27, 2013 07:17 PM|LINK
nellylou
Member
3 Points
11 Posts
Re: Keep jQuery dialog closed on back button
Feb 27, 2013 08:20 PM|LINK
When I try that the dialog doesn't open at all. I'm testing in IE9 and Firefox and it didn't open in either one.
rajendraram
Participant
812 Points
258 Posts
Re: Keep jQuery dialog closed on back button
Feb 27, 2013 08:29 PM|LINK
change
runjQueryCode("$('#dialog3').dialog({ autoOpen: false, display: 'block', width: 550, height: 350, modal: true })")nellylou
Member
3 Points
11 Posts
Re: Keep jQuery dialog closed on back button
Feb 27, 2013 08:35 PM|LINK
With that change I still have the original problem; when the back button is clicked the dialog is opened.
medelbrock
Member
729 Points
153 Posts
Re: Keep jQuery dialog closed on back button
Feb 27, 2013 09:23 PM|LINK
Your button is posting the form to the server to get javascript. Cut out the middleman by making it just a button
<input id="chpassword" type="button" value="Forgot Password?"/> <script type="text/javascript"> $("#chpassword").on("click",function(event){ $("#dialog3").dialog({ show:"blind",hide:"clip",width:550,height:350,modal:true}).appendTo("form:first"); }); </script>nellylou
Member
3 Points
11 Posts
Re: Keep jQuery dialog closed on back button
Feb 28, 2013 11:40 AM|LINK
Now only the title of the dialog opens, the content inside the dialog is not visible. I tried adding ("open") somehwere in your code which gave a javascript error, when I hit continue or ignore the entire dialog was displaying properly.
Thanks to your help, the good news is when I went to a new page and clicked back the dialog was not open! Now I just need the entire dialog to display..
Song-Tian - ...
All-Star
43715 Points
4304 Posts
Microsoft
Re: Keep jQuery dialog closed on back button
Mar 01, 2013 05:18 AM|LINK
Hi,
Try to debug with IE Developer Tools.
#How to use F12 Developer Tools to Debug your Webpages (Windows)
http://msdn.microsoft.com/en-us/library/ie/gg589507(v=vs.85).aspx
Feedback to us
Develop and promote your apps in Windows Store
nellylou
Member
3 Points
11 Posts
Re: Keep jQuery dialog closed on back button
Mar 01, 2013 11:11 AM|LINK
Yes!!! It's working! This is the code that works. Thanks for all your help!
<script type="text/javascript"> $(function () { $("#dialog3").dialog({ autoOpen: false, width: 550, height: 350, scrollable: true, modal: true, show: { effect: "blind" }, hide: { effect: "clip" } }); $("#chpassword").click(function () { $("#dialog3").parent().appendTo("form"); $("#dialog3").dialog("open"); }); }); </script>ylsv
Member
118 Points
90 Posts
Re: Keep jQuery dialog closed on back button
Jun 05, 2013 01:23 PM|LINK
i know this is the old post but I am tryiing the same thing. Could you post your complete code here. It is not working for me.
Thanks
ylsv