I just tried the code posted by KJAK (05-23-2007 11:05 AM), but it wasn't working for me.
I spent about 30 minutes trying different variations of the code, but my modalPopup object was always being returned as null, which produced a null reference on the "add_shown" call.
But, I've finally discovered the error! In the code above, KJAK escapes a double-quote character twice. That is, you used: \""
That should produce a compiler error as far as I'm concerned, but it still compiles. For some reason, that seemed to be causing the issue I was experiencing. After I removed the backslash at that point, the code worked for me. So, if anyone else has the
same issue, try the modified code below.
If Not Page.IsPostBack Then
If (Not Me.ClientScript.IsStartupScriptRegistered("Startup")) Then
Dim sb As StringBuilder = New StringBuilder()
sb.Append("<script type=""text/javascript"">")
sb.Append("Sys.Application.add_load(modalSetup);")
sb.Append("function modalSetup() {")
sb.Append(String.Format("var modalPopup = $find('{0}');", mpe1.BehaviorID))
sb.Append("modalPopup.add_shown(SetFocusOnControl); }")
sb.Append("function SetFocusOnControl() {")
sb.Append(String.Format("var textBox1 = $get('{0}');", confirmUsername.ClientID))
sb.Append("textBox1.focus();}")
sb.Append("</script>")
Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sb.ToString())
End If
End If
EndangeredMa...
Participant
1134 Points
211 Posts
Re: Set Focus on Textbox in modalPopup Panel
Dec 05, 2007 04:08 PM|LINK
I just tried the code posted by KJAK (05-23-2007 11:05 AM), but it wasn't working for me.
I spent about 30 minutes trying different variations of the code, but my modalPopup object was always being returned as null, which produced a null reference on the "add_shown" call.
But, I've finally discovered the error! In the code above, KJAK escapes a double-quote character twice. That is, you used: \""
That should produce a compiler error as far as I'm concerned, but it still compiles. For some reason, that seemed to be causing the issue I was experiencing. After I removed the backslash at that point, the code worked for me. So, if anyone else has the same issue, try the modified code below.
If Not Page.IsPostBack Then If (Not Me.ClientScript.IsStartupScriptRegistered("Startup")) Then Dim sb As StringBuilder = New StringBuilder() sb.Append("<script type=""text/javascript"">") sb.Append("Sys.Application.add_load(modalSetup);") sb.Append("function modalSetup() {") sb.Append(String.Format("var modalPopup = $find('{0}');", mpe1.BehaviorID)) sb.Append("modalPopup.add_shown(SetFocusOnControl); }") sb.Append("function SetFocusOnControl() {") sb.Append(String.Format("var textBox1 = $get('{0}');", confirmUsername.ClientID)) sb.Append("textBox1.focus();}") sb.Append("</script>") Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sb.ToString()) End If End If