Get confirm-box value via code-behind at C#

若如初见. 提交于 2019-12-25 11:51:28

问题


I want to get the value from side to confirm aspx

bool type=false;

 type=   ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "confirm('are you confirm?')", true);

if(type){
...
}

How do I get the value of?


回答1:


Doesn't sound like best of the approach (I mean you could show pop-up client side)... However, if you want to accomplish this...

You have have a hidden asp:Button on your aspx and attach a event handler to it and write the code that you want to have executed upon clicking Yes on the confirm button.

And modify your RegisterStartupScript as below

type=   ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "if(confirm('are you confirm?')) { document.getElementById('btn').click(); } ", true);



回答2:


bool type=false;

  "return confirm('are you confirm?')"

if(type){
...
}



回答3:


I was facing the same issue. The below code worked for me.

ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "if(confirm(\"Are you sure?\")){ document.getElementById('Button1').click(); }", true);
<asp:Button ID="Button1" Visible="true" SkinID="button"  OnClick="Button1_Click"  runat="server" />

Use a hidden button and write the code on click event of the button. Please note that don't use visible="false" property to make the button hidden. Instead use style="display:none"



来源:https://stackoverflow.com/questions/17920125/get-confirm-box-value-via-code-behind-at-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!