By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,733 Members | 914 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,733 IT Pros & Developers. It's quick & easy.

Confirm button in asp.net

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.