ASP.NET Web Forms FAQ: Dynamic control diakses melalui JavaScript RRS feed

  • Diskusi Umum

  • Referensikan properti control ClientID (atau UniqueID) dalam Javascript.


    protected void Page_Load(object sender, EventArgs e) 

        Button btn= new Button(); 

        btn.ID = "btn5"; 

        btn.Attributes.Add("runat", "server"); 

        btn.Attributes.Add("onclick", "pop('" + btn.ClientID + "')"); 

        btn.Text = "Test"; 





    function pop(InputBoxID) 
       var InputControl = document.getElementById(InputBoxID); 


    Atau gunakan metode berikut ini


    btn.Attributes.Add("onclick", "pop(this)"); 
    function pop(InputBox) 

     Thread terkait:

    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Rabu, 21 September 2011 03.31