在Form表单中有个id为Menu1的TextArea控件。我现在想把"Menu"&1组成的字符串转为Menu1控件,该用什么函数来实现? 谢谢!!!

解决方案 »

  1.   

    document.getElementById("Menu"+1)
      

  2.   

    试试:
    TextArea Menu1=(TextArea)Page.FindControl("Menu"+"1");
      

  3.   

    不知道VB。Net有没有提供转换函数?
      

  4.   

    FindControl()方法可以的。
    下面的示例定义了一个 Button1_Click 事件处理程序。在被调用时,此处理程序使用 FindControl 方法来在包含页上查找其 ID 属性为 TextBox2 的控件。如果找到了该控件,则使用 Parent 属性确定其父控件,并将父控件的 ID 写入页中。如果没有找到 TextBox2,则将 "Control Not Found" 写入页中。[Visual Basic]    Private Sub Button1_Click(sender As Object, MyEventArgs As EventArgs)
             ' Find control on page.
             Dim myControl1 As Control = FindControl("TextBox2")
             If (Not myControl1 Is Nothing)
                ' Get control's parent.
                Dim myControl2 As Control = myControl1.Parent
                Response.Write("Parent of the text box is : " & myControl2.ID)
             Else
                Response.Write("Control not found.....")
             End If
       End Sub[C#] 
    private void Button1_Click(object sender, EventArgs MyEventArgs)
    {
          // Find control on page.
          Control myControl1 = FindControl("TextBox2");
          if(myControl1!=null)
          {
             // Get control's parent.
             Control myControl2 = myControl1.Parent;
             Response.Write("Parent of the text box is : " + myControl2.ID);
          }
          else
          {
             Response.Write("Control not found");
          }
    }
      

  5.   

    如下:
    string txtname = "Menu" + i;
    TextBox myMenu = (TextBox)this.FindControl(txtname);
      

  6.   

    先搞清楚你的控件是不是运行在服务器端的,也就是有没有runat=server,如果有可以用
    楼上的办法,如果没有似乎要用客户端脚本实现了!