如何生成警报& ASP .Net中的确认框 [英] how to generate alert & confirm box in ASP .Net
问题描述
亲爱的,
我有带文本字段和提交按钮的webform。
我的要求点击提交按钮后,它应显示如下
如果字段为空,则应显示带有特定消息的alertbox&
如果字段包含数据if应该显示确认框是和取消
如果用户选择是,它将重定向到另一个页面或如果用户选择取消操作将取消,光标将聚焦到第一个文本框。
怎么做?
谢谢
CodeProject文章提供了很好的参考一个简单的ASP.NET服务器控件:消息框&确认框 [ ^ ]
试试这个,工作正常
< script language = < span class =code-string> javascript type = 文本/ JavaScript的跨度>>
function ValidateForm()
{
var Form = document .getElementById(' frmname');
if (Form.txtCandidateName.value == ' ')
{
alert(' 输入申请人姓名'< /跨度>);
document .getElementById(' txtCandidateName'< /跨度>)聚焦();
return false ;
}
返回 true ;
function 确认(btn)
{
var gr1;
gr1 = true ;
if ( document .getElementById( fldGraduation))
{
gr1 = false ;
gr1 = validationF();
}
如果(!gr1)
{
return false ;
}
if (确认('' 是的,我已经检查了所有细节。')){btn.style.display = ' 无跨度>; 返回 true ;} else { return false ;}
}
< / script>
< asp:Button ID = btnProceed runat = server 文字 = 继续 OnClick = btnProceed_Cli ck < span class =code-attribute> OnClientClick = 返回确认(此); / >
如果这是你的解决方案,请回答,以便其他人可以参考解决方案。
谢谢
< blockquote> Response.Write(< script> alert('+ Server.HtmlEncode(ex.Message)+')< / script>);
和
String conform =< script> if(confirm('你确定要离开页面')){document.location ='Default.aspx';}< / script>;
Response.Write(符合);
Dear All,
I have webform with textfields & with submit button.
My requirement is after clicking submit button it should show as follows
If fields are empty it should show alertbox with certain message &
if fields contains data the if should show confirm box with yes & cancel
If ther user select yes it will redirect to another page or If the user select cancel the operation will cancel & the cursor will focus to first textbox.
How to do this?
Thanks
Nice reference is available in CodeProject article A Simple ASP.NET Server Control: Message Box & Confirmation Box[^]
Try this, working fine
<script language="javascript" type="text/javascript"> function ValidateForm() { var Form=document.getElementById('frmname'); if(Form.txtCandidateName.value=='') { alert('Enter Name of Applicant '); document.getElementById('txtCandidateName').focus(); return false; } return true; function ConfirmALL(btn) { var gr1; gr1= true; if(document.getElementById("fldGraduation")) { gr1= false; gr1= validationF(); } if(!gr1) { return false; } if(confirm('Yes, I have Checked all the details.')){btn.style.display='none'; return true;}else{return false;} } </script>
<asp:Button ID="btnProceed" runat="server" Text="Proceed" OnClick="btnProceed_Click" OnClientClick="return ConfirmALL(this);" />
Make it answer if this is your solution, so that other can refer the solution.
Thanks
Response.Write("<script>alert('"+ Server.HtmlEncode(ex.Message) + "')</script>");
and
String conform = "<script>if (confirm('Are you sure you want to leave the page')){document.location='Default.aspx';}</script>";
Response.Write(conform );
这篇关于如何生成警报& ASP .Net中的确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!