字符串生成器-输入按钮模块
本文关键字:输入 按钮 模块 字符串 | 更新日期: 2023-09-27 17:58:24
我正在尝试通过字符串生成器调用C#模块来创建一个按钮。不管我在做什么,我似乎都做不到。我需要做JavaScript吗???
StringBuilder sb = new StringBuilder("");
已尝试:
sb.Append("<input type='"button'" id='"Button1'" value='"Click Me'" runat='"server'" onserverclick='"Button1_Click'" />");
已尝试:
sb.Append("<button type='"button'" onserverclick='"Button1_Click'" runat='"server'" id='"Btn1'">Click Me</button>");
C#代码:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Testing");
}
protected void Page_Load(object sender, EventArgs e)
{
Button button = new Button { ID = "btn1", Text = "Click Me" };
button.Click += btn_Click;
PlaceHolder btnPlaceHolder = new PlaceHolder();
btnPlaceHolder.Controls.Add(button);
}
private void btn_Click(object sender, EventArgs e)
{
Response.Write("Testing");
}
使用asp:Button代替
sb.Append("<asp:Button OnClick='"Button1_Click'" runat='"server'" ID='"Btn1'">Click Me</asp:Button>");