[英]Confirmation message from the ASP.NET code behind file
I have a login screen Login.aspx after login I want to show a confirmation message saying 登录后我有一个登录屏幕Login.aspx,我想显示一条确认消息,
"You are being redirected to the Demo page. Do you want to continue?", “您将被重定向到“演示”页面。是否要继续?”,
if the user clicked yes, I need to redirect them to a demo page. 如果用户单击“是”,则需要将他们重定向到演示页面。 Other wise redirect to another home page.
其他明智的重定向到另一个主页。 How can I do this?
我怎样才能做到这一点?
I want something like the following... 我想要以下内容...
protected void Login_Click(object sender, ImageClickEventArgs e)
{
//some validation and calculations..
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "confirm('You are redirecting to Demo page ". Do you want to continue" ?');", true);
//My doubt is this
If(ok button clicked)
{
//redirect to demo page
}
else
{
//redirect to home page
}
}
You wont get the result of confirm on server side. 您不会在服务器端得到确认结果。 You can call a javascript function RegisterStartupScript and put this confirm dialog in that function.
您可以调用javascript函数RegisterStartupScript并将此确认对话框放入该函数中。
Although you can somehow send value of confirm on server side using postback of some ajax call but I do not see any reason for that. 虽然您可以使用某些Ajax调用的回发以某种方式在服务器端发送确认值,但是我看不到任何原因。
Code behind 后面的代码
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "RedirectDecision();", true);
Html HTML
<script type="text/javascript">
function RedirectDecision()
{
if(confirm('You are redirecting to Demo page ". Do you want to continue" ?'))
window.location = "http://www.yoururlFirst.com";
else
window.location = "http://www.yoururlSecond.com";
}
</script>
You can't do that. 你不能那样做。 You can call a client side function by setting
OnClientClick
. 您可以通过设置
OnClientClick
来调用客户端功能。 If user will press confirm than code behind
function will be called. 如果用户按确认,则将调用功能
code behind
。 Have a look at below example 看下面的例子
<asp:Button ID="Button2" OnClick="Login_Click" OnClientClick="return UserConfirmation()" runat="server" Text="Login" />
function UserConfirmation() {
if(confirm('You are redirecting to Demo page ". Do you want to continue" ?'))
return true;
else
return false;
}
Here if user will press ok
than code behind
function will be called other wise it won't 在这里,如果用户按“
ok
其他方式调用该函数code behind
否则将不会
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.