JavaScript警告问题 [英] Javascript alert problem
问题描述
我想补充一个警告框,让用户可以选择是或否或确定和取消,但它不工作correctly.I必须做一个数据库检查是在C做尖锐而不仅仅是链接功能按钮点击事件。这是我想做到这一点我的第一次。我使用Visual Studio 2010中,我不知道如果我的code是正确的。任何人都可以请指导我,如果我错了。
私人无效AlertWithConfirmation()
{
的Response.Write(< SCRIPT LANGUAGE =JavaScript的'>中);
回复于(功能onsub());
的Response.Write({);
的Response.Write(回归确认(\\你确定\\));
的Response.Write(});
回复于(&下; /脚本>中);
}
这是我的完整的C#code:
保护无效Import_Click(对象发件人,EventArgs的发送)
{
如果(!Validation.ValidateDateFormat(dateField.Text))
{
errorMessageLabel.Text =无效的日期格式,例如:2011/1/1应该是01/01/2011
}
其他
{
//验证数据是否已经导入
如果(BusinessLayerHandler.isImported(dateField.Text)== FALSE)
{
尝试
{
如果(BusinessLayerHandler.isInProgress(dateField.Text)==真)
{
AlertWithConfirmation();
}
}
抓住
{
// catch错误
}
}
否则,如果(BusinessLayerHandler.isImported(dateField.Text)==真)
{
警报(那日期已经进口);
}
}
您code是完全正确的。只有语法错误。刚开始的线 - 双引号之前删除\\>
的Response.Write(回归确认(\\你确定\\));结果
与此行结果替换
的Response.Write(返回确认(你确定\\));
I am trying to add an alert box so that the user can choose either Yes or No or Ok and Cancel, but it is not working correctly.I have to do a database check which is done in c sharp not just link that function to a button clicked event. It is my first time I am trying to do this. I am using visual studio 2010. I am not sure if my code is correct. Can anyone please guide me if I am mistaken.
private void AlertWithConfirmation()
{
Response.Write("<script language='javascript'>");
Response.Write("function onsub() ");
Response.Write("{ ");
Response.Write("return confirm(\"Are you sure?\")");
Response.Write("} ");
Response.Write("</script>");
}
This is my full C# Code:
protected void Import_Click(object sender, EventArgs e)
{
if (!Validation.ValidateDateFormat(dateField.Text))
{
errorMessageLabel.Text = "Invalid Date Format, for example: 1/1/2011 should be 01/01/2011";
}
else
{
//Validation to check if data is already imported
if (BusinessLayerHandler.isImported(dateField.Text) == false)
{
try
{
if (BusinessLayerHandler.isInProgress(dateField.Text)== true)
{
AlertWithConfirmation();
}
}
catch
{
//catch error
}
}
else if (BusinessLayerHandler.isImported(dateField.Text) == true)
{
Alert("That date was already imported");
}
}
your code is absolutely correct. only syntax error. just remove "\" before starting the double quotes in the line->
Response.Write("return confirm(\"Are you sure?\")");
replace with this line
Response.Write("return confirm("Are you sure?\")");
这篇关于JavaScript警告问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!