Confirm button in asp.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Help, I’m trying to implement a confirm button on an asp.net page. I have it
attached to a asp:button control. In the button1 click event I call the
CreateConfirmBox subroutine. The Box comes up with the yes/No option ok. My
problem or question is: How do I determine which button was pressed? Below
are the 2 routines I’m using.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CreateConfirmBox(Button1, "Do you want to close?")
End Sub


Public Shared Sub CreateConfirmBox(ByRef btn As WebControls.Button, _
ByVal strMessage As String)
btn.Attributes.Add("onclick", "return confirm('" & strMessage & "');")

End Sub

Any help will be appreciated,
Logger
 
Hi,

On the client side, confirm returns true if OK was clicked and false for
Cancel. As per your code below, postback will happen only when user clicked
on OK. So, on the server-side, you can assume that OK was pressed on the
client-side.


Help, I'm trying to implement a confirm button on an asp.net page. I have
it
attached to a asp:button control. In the button1 click event I call the
CreateConfirmBox subroutine. The Box comes up with the yes/No option ok. My
problem or question is: How do I determine which button was pressed? Below
are the 2 routines I'm using.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
CreateConfirmBox(Button1, "Do you want to close?")
End Sub


Public Shared Sub CreateConfirmBox(ByRef btn As WebControls.Button, _
ByVal strMessage As String)
btn.Attributes.Add("onclick", "return confirm('" & strMessage &
"');")

End Sub

Any help will be appreciated,
Logger
 
Ok, but where do I check for the return true, In the Createconfirmbox or the
button1_click routine and How?
Logger
 
Hi,
You don't get the return value of confirm() on the server side directly. If
the button1_click is executed, it means the return value from confirm() is
true (per your logic). If the confirm() returns false (because user clicked
Cancel), then button1_click will not get executed since there is no
postback.

HTH,

Ok, but where do I check for the return true, In the Createconfirmbox or the
button1_click routine and How?
Logger
 
Hi, Another problem with my routine. On the first pass it doesn’t seem to
work, It doesn't show the confirm box. I have to run it twice before it
displays. This of course is no good. Any suggestion on what I can do?
Logger
 
You are attaching the JS onClick script for confirm in the server-side
button click event. So, the confirm box appears only after you have pressed
the button at least once. If you have the CreateConfirmBox() in Page_Load,
it should prompt at the first time itself.

Sub Page_Load()
If (Not IsPostback) Then CreateConfirmBox(...)
End Sub


Hi, Another problem with my routine. On the first pass it doesn't seem to
work, It doesn't show the confirm box. I have to run it twice before it
displays. This of course is no good. Any suggestion on what I can do?
Logger
 
Back
Top