none
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"; 

        this.form1.Controls.Add(btn); 

    }

     

     

    function pop(InputBoxID) 
    { 
       var InputControl = document.getElementById(InputBoxID); 
       alert(InputControl.value); 
    }

     

    Atau gunakan metode berikut ini

     

    btn.Attributes.Add("onclick", "pop(this)"); 
    function pop(InputBox) 
    { 
       alert(InputBox.value); 
    }

     Thread terkait: http://forums.asp.net/p/1239593/2260331.aspx#2260331


    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
    Moderator