基于服务器端逻辑触发javascript确认(ASP.NET)
有没有办法让下面的代码工作?基本上,当我单击 btnOne 时,如果 a 为 true,我希望它弹出确认框。如果我按 yes,那么它将执行 btnTwo 方法。否则,它不会做任何事情。目前,它没有弹出窗口,我不知道为什么。有人可以指出我正确的方向吗?或者可能让我知道实现这一目标的其他方法。
任何信息将不胜感激。
例如:
public void btnTwo(object sender, EventArgs e)
{
//Do some processing
}
public void btnOne(object sender, EventArgs e)
{
if( a == true )
btnTwo.Attributes["onClick"] = "return confirm('test');"
btnTwo(sender, new EventArgs());
}
Is there a way to make the following code works? Basically, when I click on btnOne, If a is true, i expect it to popup the confirm box. And If i press yes, then it will execute btnTwo method. Otherwise, it will not do anything. At the moment, it doesn't do the popup and i am not sure why. Can someone please point me in the right direction? or possibly let me know other way of achieving this.
Any information would be much appreciated.
For example:
public void btnTwo(object sender, EventArgs e)
{
//Do some processing
}
public void btnOne(object sender, EventArgs e)
{
if( a == true )
btnTwo.Attributes["onClick"] = "return confirm('test');"
btnTwo(sender, new EventArgs());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你混合了很多客户端和服务器端?你能在客户端检查“a”(隐藏字段)吗?
或者在检查后面代码中的值后,添加带有确认的启动脚本,然后在“是”上“单击”javascript 中的第二个按钮。
和标记:
I think you are mixing to much client and server side? Could you check "a" (hidden field) on client side?
Or after check value in code behind add start up script with confirm and then on yes "click" second button in javascript.
And markup:
确保已到达该代码,并使用
OnClientClick
代替:Make sure that the code is being reached, and use
OnClientClick
instead: