confirmation and passing values

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!
 
M

Milosz Skalecki [MCAD]

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

Regards
 
R

rsht

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.
 
M

Milosz Skalecki [MCAD]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top