0

我正在使用下面的代码在后面的代码中创建一个按钮,并为该按钮创建确认消息框。但它不起作用请帮我创建这个..

Button btn2 = new Button();
btn2.Attributes.Add(
    "OnClientClick", 
    "if (confirm(''Are you sure you want to add this estimate data?')) return;");

if(true) 
{
    //Do something
}
4

5 回答 5

1
btn2.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to add this    estimate data??')"); 
于 2012-08-09T05:43:09.887 回答
1

您可以使用以下代码:

btn2.Attributes.Add("onclick", "return confirm('Are you sure you want to add this estimate data?');")
于 2012-08-09T05:49:06.600 回答
1

您可以将 ajaxcotoroll 工具包引用添加到您的网站,并为每个按钮动态创建确认

Button btn2 = new Button();
btn.ID="buttonID";
ConfirmButtonExtender confirm = new ConfirmButtonExtender();
confirm.TargetControlID = "buttonID";
confirm.ConfirmText="Are you sure you want to add this    estimate data??'";
于 2012-08-09T05:57:21.853 回答
1

您也可以使用以下代码:-

btn2.Attributes["onClick"] = "return confirm('Are you sure you want to add this   estimate data??');"
于 2012-08-09T06:03:41.250 回答
0

试试这个鳕鱼:

 Button yourbtnid = new Button();
 yourbtnid.ID="Button1";
 ConfirmButtonExtender conf = new ConfirmButtonExtender();
 conf.TargetControlID = "Button1";
 conf.ConfirmText="Are you sure you want to add this    estimate data??'";

这是使用 Ajaxcontroll 调用..

或者

Button yourbtnid = new Button();
yourbtnid.Attributes.Add(
     "OnClientClick", 
     "return confirm('Are you sure you want to add this    estimate data??');");
于 2012-08-09T06:10:37.860 回答