default.aspx
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</asp:Content>
default.aspx.vb
Public Class _Default
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
For x As Int64 = 1 To 20
Dim Control As New WebUserControl1
Control = LoadControl("WebUserControl1.ascx")
Control.ID = "UserControl" & x.ToString
Me.Panel1.Controls.Add(Control)
AddHandler Control.ControlDataSaved, AddressOf Me.Operations_ControlDataSaved
Next
End Sub
Protected Sub Operations_ControlDataSaved(ByVal sender As Object, ByVal e As EventArgs)
For x As Int64 = 0 To Me.Panel1.Controls.Count - 1
If Me.Panel1.Controls.Item(x).ID = sender.ID Then
Dim Control As WebUserControl1 = Me.Panel1.FindControl(Me.Panel1.Controls.Item(x + 1).ID)
Control.FindControl("Textbox1").Focus()
''' This code behaves the same way as the uncommented code.
'Dim ControlID As String = Me.Panel1.Controls.Item(x + 1).ClientID & "_TextBox1"
'Dim sm As ScriptManager = ScriptManager.GetCurrent(Me)
'sm.SetFocus(ControlID)
Exit For
End If
Next
End Sub
End Class
WebUserControl1.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="WebUserControl1.ascx.vb" Inherits="WebApplication1.WebUserControl1" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server" TabIndex="1"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" TabIndex="-1" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
WebUserControl.ascx.vb
Public Class WebUserControl1
Inherits System.Web.UI.UserControl
Public Event ControlDataSaved As EventHandler
Protected Sub OnControlDataSaved(ByVal e As EventArgs)
RaiseEvent ControlDataSaved(Me, e)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.OnControlDataSaved(e)
End Sub
End Class
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
As it turns out, The code I was using was the exact code I needed to do what I wanted to do - it just didn't work in IE8. I tested 4 other browsers (Safari, Chrome, Opera, and Firefox) and all worked as they should have given the code I was using.
I finally opened a ticket with Microsoft and found out that the behavior I described in my original post was specific to IE8 running in IE8 standards mode. I was given a couple of work around to try. The first was to call a set focus script via a setTimeout call of 0. Given the architecture of my application, this would have required a substantial amount of rework. The other was to set the compatability view of the page to IE=EmulateIE7. (Instruction on how to do this are at http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx) This worked like a champ and the page and code are now behaving as expected.
Microsoft also informed me that they tested my code in IE version 6,7, and 9 beta and the code worked as it should in each of those version - only IE8 seems to be affected.
Thanks to all of the folks over at Microsoft for giving me a hand with this.
Kelly