如何在javascript脚本中获取控件属性的值???

解决方案 »

  1.   

    属性有多种,服务器端的属性可以
    var str = "<%=服务器空间ID.服务器属性%>"
    客户端属性,可以
    document.getElementById("<%=服务器空间ID.ClientID%>").属性名字或者
    document.getElementById("<%=服务器空间ID.ClientID%>").getAttribute("属性名字")
      

  2.   

    可参考
    http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp
      

  3.   

    当控件的服务器控件ID是个变量时,在这句中"<%=服务器空间ID.服务器属性%>",该如何写呢?
      

  4.   

    public string a = "TextBox1";aspxalert('<%=((TextBox)Page.FindControl(this.a)).ClientID%>')
      

  5.   

    例子<script>
    alert('<%=((TextBox)Page.FindControl(this.a)).Text%>')
    </script>
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
     <asp:TextBox id="TextBox1" runat="server">测试</asp:TextBox>
    </form>
    </body>public string a = "TextBox1";private void Page_Load(object sender, System.EventArgs e)
    {}
      

  6.   

    public string a = "TextBox1";aspxdocument.all("<%=a%>").属性名字
      

  7.   

    方法一:       document.getElementById("<%=PMBName.ClientID %>").value="<%=((PMBase)Page.FindControl(this.id)).name%>";
    方法二:      document.getElementById("<%=PMBName.ClientID %>").value=document.all("<%=this.id%>").name;
    都提示“ASP.jianmotest_aspx”并不包含“id”的定义
    其中PMBase为自定义的组件.
    http://community.csdn.net/Expert/topic/4860/4860674.xml?temp=5.817813E-02
      

  8.   

    上面的id是我传入的参数变量.function showpanel(id){}
      

  9.   

    如果在脚本中不能直接读取控件变量的属性,那么我可以用Ajax技术读取session的值,但是我在我在Name属性中设置session时,当设置属性时有问题,如果先置好属性,再打开session则能够在前台代码中得到session的值,但是控件在工程中不正常,但是运行时是正常的.   
     public string Name
            {
                get
                {
                    object o = ViewState["Name"];
                    return (o == null) ? "" : (string)o;
                   
                }
                set
                {
                    ViewState["Name"] = value;
                    this.lblName.Text = value;
                    HttpContext.Current.Session[this.ID + "PMBaseName"] = value;
                }
           
            }