ASP.NET Dynamic Controls FAQ: Dynamic controls โดยใช้ JavaScript
-
27 กุมภาพันธ์ 2555 8:42ผู้ดูแลASP.NET Dynamic Controls FAQ: Dynamic controls โดยใช้ JavaScript
Supa Sethasiripong [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.
ตอบทั้งหมด
-
27 กุมภาพันธ์ 2555 8:46ผู้ดูแล
อ้างอิงคุณสมบัติClientID (หรือUniqueID) ของcontrol ใน 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);
}
หรือใช้ method ต่อไปนี้
btn.Attributes.Add("onclick", "pop(this)");
function pop(InputBox)
{
alert(InputBox.value);
}
ฟอรัมที่เกี่ยวข้อง
http://forums.asp.net/p/1239593/2260331.aspx#2260331
Supa Sethasiripong [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.
- ทำเครื่องหมายเป็นคำตอบโดย supa_sModerator 28 กุมภาพันธ์ 2555 2:26