如何在服务器端调用不同的页面确认确定并取消 [英] How to call different pages on server side confirm ok and cancel
问题描述
I want to redirect the page on other form when click on ok of confirm and when click on cancel then cancel how i do this.. i use below code but this is not redirect to another page. i want to use the server side confirm not client side
protected void Page_Load(object sender, EventArgs e)
{
string message1 = "Do you want to Submit?";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("return confirm('");
sb.Append(message1);
sb.Append("');");
ClientScript.RegisterOnSubmitStatement(this.GetType(), "alert", sb.ToString());
}
On button click i call
protected void btnMsg_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("Response.Redirect('WebForm2.aspx'){");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
}
}
我的尝试:
What I have tried:
I want to redirect on webform 2 on confirm ok button click and on cancel i move to another..but this is not done plz recmond how i redirect this
推荐答案
System.Text.StringBuilder sb = new System.Text .StringBuilder();
sb.Append(< script type ='text / javascript'>);
sb.Append(window.onload = function(){);
sb.Append(Response.Redirect('WebForm2.aspx'){);
sb.Append(< /脚本>);
ClientScript.RegisterClientScriptBlock(this.GetType(),alert,sb.ToString());
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("Response.Redirect('WebForm2.aspx'){");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
除了明显的语法rror,你也试图从客户端代码调用服务器端方法( Response.Redirect
)。
用以下内容替换事件处理程序的内容:
Apart from the obvious syntax error, you're also trying to invoke a server-side method (Response.Redirect
) from client-side code.
Replace the content of your event handler with:
protected void btnMsg_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}
我想使用服务器端确认不是客户端
i want to use the server side confirm not client side
没有服务器端确认。除非通过返回响应中的内容,否则在服务器上运行的代码无法向客户端显示任何UI。向用户显示消息的唯一方法是通过客户端代码。
There is no "server-side confirm". Code running on the server cannot display any UI to the client, except by returning content in the response. The only way to display a message to the user is via client-side code.
检查以下文章 -
服务器端(代码隐藏)是否ASP.Net中没有确认消息框 [ ^ ]
希望,它有帮助:)
Check following article-
Server Side (Code Behind) Yes No Confirmation Message Box in ASP.Net[^]
Hope, it helps :)
这篇关于如何在服务器端调用不同的页面确认确定并取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!