confirmation and passing values

  • Thread starter Thread starter rsht
  • Start date Start date
R

rsht

I am new to the ASP.Net and need some helps.

In ASP, page one can have a button event "confirm()" to pop-up a yes
or no window:
<form ... action="page2" >
....
<input onClick="confirm();">
</form>
and if user click yes to onfirm, the function can have form.submit to
post the form values to page2

Now I am having trouble to write aspx pages to do the same. Would
anyone can give some helps?

Thanks a lots!
 
<asp:Button runat="server" ID="whatever" OnClientClick="return
confirm('question...?')"/>

Regards
 
Thanks Milosz!

Could you tell me how I can act differently base on which button user
clicks when responds to the "question...?"? Basically, this is a
confirmation for the database update with the current webform input.
If user click OK, the action should update the database with the user
inputs in the controls within the webform.
 
The code i posted prevents the form from being posted if users click 'cancel'
button (nothing will happen). Amending the code to post the value to the
server, and then you may decide what to do:

<asp:Buton runat="server" ID="btn"/>
<asp:HiddenField runat="server" ID="hdn" />
<script type="text/javacsript">
function askUser()
{
document.getElementById('<%=hdn.ClientID%>').value = confirm('question');
}
</script>

-- c# code behinnd --
protected void btn_Click(object sender, EventArgs e)
{
bool confirmed = Convert.ToBoolean(hdn.Value);

if (confirmed)
{
// do something
}
else
{
// do something else
}

}
-- end c# code behind --

Hope this helps
 
Back
Top