[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1045
  • Last Modified:

updatepanel and text box set focus

Hi Expert,

I used a updatepanel,  inside this panel, I have two radio buttons and two regular panels, when I click on radio button1, I want panel one to show and inside panel one I want set focus on txtFirstName, I write code to do it, but it do not work, How to make it works?

code fragment are here

Protected Sub rdType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdType.SelectedIndexChanged
        If (rdType.SelectedItem.Value = "new") Then
            Me.Panelone.Visible = true
            Me.txtfirstName.Focus()

thanks in advance
0
dshi15
Asked:
dshi15
  • 5
  • 2
1 Solution
 
David H.H.LeeCommented:
Hi dshi15,
I've tested the code that mentioned, it's working fine under my test case. Please post the design code here in case it not match yours.
Check my tested code here:
aspx
============
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
          <ContentTemplate>
            <asp:RadioButtonList ID="rdType" runat=server AutoPostBack="True">
                <asp:ListItem Value="new">Option 1</asp:ListItem> 
                <asp:ListItem Value="old">Option 2</asp:ListItem> 
            </asp:RadioButtonList> 
            <asp:Panel ID="Panelone" runat=server Visible=false>Panel one<asp:TextBox ID="txtfirstName" runat=server></asp:TextBox></asp:Panel> 
            <asp:Panel ID="Paneltwo" runat=server Visible=false>Panel two<asp:TextBox ID="txt1" runat=server></asp:TextBox></asp:Panel> 
        <asp:ScriptManager ID="ScriptManager1" runat="server">
              </asp:ScriptManager>
          </ContentTemplate> 
        </asp:UpdatePanel>
          
    </div>
    </form>
</body>
 
code-behind
============
Protected Sub rdType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rdType.SelectedIndexChanged
        If (rdType.SelectedItem.Value = "new") Then
            Me.Panelone.Visible = True
            Me.txtfirstName.Focus()
        End If
    End Sub

Open in new window

0
 
dshi15Author Commented:
thanks, I will test code and let you know.
0
 
dshi15Author Commented:
I tested code, panel one is show and txtfirstname box is show but cursor not jump inside the box.

<body>
    <form id="form1" runat="server">
   
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
              </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
          <ContentTemplate>
            <asp:RadioButtonList ID="rdType" runat="server" AutoPostBack="True">
                <asp:ListItem Value="new">Option 1</asp:ListItem>
                <asp:ListItem Value="old">Option 2</asp:ListItem>
            </asp:RadioButtonList>
            <asp:Panel ID="Panelone" runat="server" Visible="false">Panel one<asp:TextBox ID="txtfirstName" runat="server"></asp:TextBox></asp:Panel>
            <asp:Panel ID="Paneltwo" runat="server" Visible="false">Panel two<asp:TextBox ID="txt1" runat="server"></asp:TextBox></asp:Panel>
       
          </ContentTemplate>
        </asp:UpdatePanel>
         
   
    </div>
    </form>
</body>


Protected Sub rdType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles rdType.SelectedIndexChanged
        If (rdType.SelectedItem.Value = "new") Then
            Me.Panelone.Visible = True
            Me.txtfirstName.Focus()
        End If
    End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
dshi15Author Commented:
I need to mention I have several text box in panel one and I let cursor set in txtfirstname box, so client can fill information.
0
 
dshi15Author Commented:
If i comment on updatepanel, it works fine. I used IE7.

<body>
    <form id="form1" runat="server">
   
    <div>
    <%--<asp:ScriptManager ID="ScriptManager1" runat="server">
              </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
          <ContentTemplate>--%>
            <asp:RadioButtonList ID="rdType" runat="server" AutoPostBack="True">
                <asp:ListItem Value="new">Option 1</asp:ListItem>
                <asp:ListItem Value="old">Option 2</asp:ListItem>
            </asp:RadioButtonList>
            <asp:Panel ID="Panelone" runat="server" Visible="false">Panel one
            <asp:TextBox ID="txtfirstName" runat="server"></asp:TextBox>
            <asp:TextBox ID="txtlastName" runat="server"></asp:TextBox>
            </asp:Panel>
            <asp:Panel ID="Paneltwo" runat="server" Visible="false">Panel two<asp:TextBox ID="txt1" runat="server"></asp:TextBox></asp:Panel>
       
       <%--   </ContentTemplate>
        </asp:UpdatePanel>--%>
         
   
    </div>
    </form>
</body>
0
 
dshi15Author Commented:
I found solution online. Thanks.

Me.ScriptManager1.SetFocus(txtfirstName)
0
 
David H.H.LeeCommented:
Hi dshi15,
Ok, perhaps your design code is more complicated. I'm glad to hear you find your preferred solution and you may request admin to make this PAQ with points refund.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now