470,602 Members | 1,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

Confirm button in asp.net

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
Jul 21 '05 #1
5 8803
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.
"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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
Jul 21 '05 #2
Ok, but where do I check for the return true, In the Createconfirmbox or the
button1_click routine and How?
Logger

"Shiva" wrote:
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.
"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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

Jul 21 '05 #3
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,

"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Ok, but where do I check for the return true, In the Createconfirmbox or the
button1_click routine and How?
Logger

"Shiva" wrote:
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.
"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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

Jul 21 '05 #4
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

"Shiva" wrote:
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,

"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Ok, but where do I check for the return true, In the Createconfirmbox or the
button1_click routine and How?
Logger

"Shiva" wrote:
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.
"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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


Jul 21 '05 #5
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
"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
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

"Shiva" wrote:
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,

"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Ok, but where do I check for the return true, In the Createconfirmbox or the button1_click routine and How?
Logger

"Shiva" wrote:
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.
"Logger" <Lo****@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
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


Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Doug O'Leary | last post: by
4 posts views Thread by @sh | last post: by
5 posts views Thread by Logger | last post: by
8 posts views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.