单击取消时,不应填充该值 [英] on clicking cancel the value shouldn't populate
问题描述
您好,我创建了一个按钮"XX".单击此按钮时,应该会弹出一个对话框,提示您确定要加载数据吗?",如果是,则应加载..如果我单击取消"不应该填充我数据库中的数据..
Hi i have created a button say"XX"..On clicking this button it should pop up a dialog box saying "Are you sure you wanna load the data?"If yes it should load..if i click cancel it shouldn''t populate the data in my database..
<asp:Button ID="button1" runat="server" align="left" BackColor="#CCCCCC" Font- Bold="True" Text="XX" OnClick="button1_click"/>
<Ajx1:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="button1" ConfirmText="Are you sure you want to load data?"
önClientCancel="cancelClick" Enabled="True" />
我用来填充数据的代码是
And my code to populate the data is
protected void button1_click(object sender, EventArgs e)
{
seph x= new seph();
x.Date = DateTime.Now;
x.name= Membership.GetUser().UserName;
dc.sephs .InsertOnSubmit(x);
dc.SubmitChanges();
}
仅当我单击对话框上的yes时,此代码才应填充数据...并且单击取消时应不填充数据库中的任何数据...但是到目前为止,即使单击取消也可以填充数据.有人告诉您是否需要任何修改?
This code should populate the data only when I click yes on my dialog box...and should not populate any data in my DB when I click cancel...But as of now even when I click cancel its populating the data..Can some one tell whether there is any modification required??
推荐答案
您甚至不需要扩展程序就可以进行修改.一个简单的按钮就可以解决问题.
此处:
You don''t even need an extender to do it. A simple button would do the trick.
Here:
<asp:Button ID="button2" runat="server" align="left" BackColor="#CCCCCC"
Font-Bold="True" Text="XX"
onClientClick="if(!confirm('Are you sure you want to delete this entry?')) return false;"
onclick="button2_Click"/>
现在,如果有人同意,那么server onclick
后面的代码将被触发,否则将被触发.
更新:我更新了上面的代码段.确认文本用双引号引起来,需要用单引号引起来.
Now, if person agrees then the code behind server onclick
will be triggered or else not.
UPDATE: I updated the snippet above. Confirm text was in double quotes that needs to be in single quotes.
用这个
在page_load事件中,为按钮添加onclick属性:
Hi,
use this,
in page_load event add the onclick attribute for the button:
button1.Attributes.Add("onclick", "return fnConfirm();");
这是您的按钮结构.保持原样.
This is your button structure. Let it be like as it is.
<asp:Button ID="button1" runat="salign="left" BackColor="#CCCCCC" Font- Bold="True" Text="XX" OnClick="button1_click"/>
编写javascript功能:
write javascript fuction:
function fnConfirm(){
if(confirm("Are you sure you wanna load the data?")){
return true;
}
return false;
}
这将为您提供帮助.通过此代码,您可以了解流程.
并请从您的代码中删除ConfirmButtonExtender.
祝一切顺利.
-AK
This will help you. And through this code you can understand the flow.
And please remove ConfirmButtonExtender from your code.
All the best.
-AK
这篇关于单击取消时,不应填充该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!