ASP.NET 中的 Javascript 警报
我想在我的 ASP.NET 页面中使用 Javascript Alert 功能。
例如这样;
Response.Write("<script language=javascript>alert('ERROR');</script>);
但是,这行不通。
我在这里问我做错了什么,每个人都建议我使用 RegisterScriptBlock
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), " ", "alert('ERROR')",true);
但我不想使用它,因为它与 PostBack
一起使用,
如果没有 PostBack
,我该如何做到这一点?
编辑:例如使用;
try
{
string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;
SqlConnection myConnection = new SqlConnection(strConnectionString);
myConnection.Open();
string hesap = Label1.Text;
string musteriadi = DropDownList1.SelectedItem.Value;
string avukat = DropDownList2.SelectedItem.Value;
SqlCommand cmd = new SqlCommand("INSERT INTO AVUKAT VALUES (@MUSTERI, @AVUKAT, @HESAP)", myConnection);
cmd.Parameters.AddWithValue("@HESAP", hesap);
cmd.Parameters.AddWithValue("@MUSTERI", musteriadi);
cmd.Parameters.AddWithValue("@AVUKAT", avukat);
cmd.Connection = myConnection;
SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
Response.Redirect(Request.Url.ToString());
myConnection.Close();
}
catch (Exception)
{
Response.Write("<h2>ERROR</h2>");
}
I want to use Javascript Alert function in my ASP.NET page.
For example like this;
Response.Write("<script language=javascript>alert('ERROR');</script>);
But, this doesn't work.
I ask in here what am i doing wrong and everyone suggest me using RegisterScriptBlock
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), " ", "alert('ERROR')",true);
But i don't want use it because it's working with PostBack
How can i do that without PostBack
?
EDIT: For example for using;
try
{
string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;
SqlConnection myConnection = new SqlConnection(strConnectionString);
myConnection.Open();
string hesap = Label1.Text;
string musteriadi = DropDownList1.SelectedItem.Value;
string avukat = DropDownList2.SelectedItem.Value;
SqlCommand cmd = new SqlCommand("INSERT INTO AVUKAT VALUES (@MUSTERI, @AVUKAT, @HESAP)", myConnection);
cmd.Parameters.AddWithValue("@HESAP", hesap);
cmd.Parameters.AddWithValue("@MUSTERI", musteriadi);
cmd.Parameters.AddWithValue("@AVUKAT", avukat);
cmd.Connection = myConnection;
SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
Response.Redirect(Request.Url.ToString());
myConnection.Close();
}
catch (Exception)
{
Response.Write("<h2>ERROR</h2>");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅来自 MSDN 的注释:
所以,我认为
ClientScriptManager.RegisterStartupScript
方法是你所需要的:See a note from MSDN:
So, I think
ClientScriptManager.RegisterStartupScript
method is what you need:在您的代码中您忘记了引号。我刚刚在这样的示例页面中尝试过它:
并且它有效。您将 Response.Write 放在代码中的什么位置?你能提供更多细节吗?你想让我做什么?
In your code you forgot the quotation mark. I just tried it in a sample page like this:
and it worked. Where did you place the Response.Write in your code? Could you give some more details? What do you want to do?
为了向用户显示警报消息,在网页中我有一个代码看看这个
For displaying an alert message to the User, in a webpage i have a code have a look at this
尝试使用 RegisterStartupscript 来注册脚本。
请参阅:http://msdn.microsoft.com /en-us/library/system.web.ui.page.registerstartupscript.aspx
try using RegisterStartupscript for registering the script.
Refer : http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript.aspx