none
ajax控件tabcontainer中怎么实现 textbox.focus() RRS feed

  • 问题

  • 如何使ajax控件tabcontainer中其他控件(如textbox)获得焦点?请各位大侠指点!!!
    我想点击Button后使textbox获得焦点(Button和textbox都在tabcontainer的标签页中),
    protected void button_Click(object sender, EventArgs e)
    {
    TextArea1.Focus();
    }
    这样不能实现!
    标签页有3页,Button和textbox都在tabcontainer的第三页中
    <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
    请问这代码应该怎么写?
    2010年2月11日 7:57

答案

  •        protected void Button1_Click(object sender, EventArgs e)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "<script> window.setTimeout(\"$find('" + TabContainer1.ClientID + "').set_activeTabIndex(2);$get('" + TextBox1.ClientID + "').focus();\", 500);</script>", false);

            }

        <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1">
            <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
          <ContentTemplate>
              <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><asp:TextBox ID="TextBox1"
                  runat="server"></asp:TextBox>
     </ContentTemplate>  </cc1:TabPanel>
        </cc1:TabContainer>

    2010年2月11日 10:49

全部回复

  • 没有人会吗?UP!UP!
    2010年2月11日 8:40
  •        protected void Button1_Click(object sender, EventArgs e)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "<script> window.setTimeout(\"$find('" + TabContainer1.ClientID + "').set_activeTabIndex(2);$get('" + TextBox1.ClientID + "').focus();\", 500);</script>", false);

            }

        <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1">
            <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
            </cc1:TabPanel>
            <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
          <ContentTemplate>
              <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><asp:TextBox ID="TextBox1"
                  runat="server"></asp:TextBox>
     </ContentTemplate>  </cc1:TabPanel>
        </cc1:TabContainer>

    2010年2月11日 10:49