• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

How to trap the OK cancel click for a client script


I am using the registerclientscript method to display a pop up confirm dialog with OK and cancel butons on some condition wihtin my asp.net page.
How do I trap which button the user clicked within my client code
If gRows.SelectionData.Rows.Count <= 1 Then
                Dim msgDesc As String = "confirm('No codes have been selected.\n\n Click OK to continue.');"                
                ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "Confirm", msgDesc, True)               
                Exit Sub
            End If

Open in new window

0
countrymeister
Asked:
countrymeister
  • 5
  • 4
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
"confirm" basically returns true (for OK) or false (for Cancel) so you can either dump the return value somewhere for future use or wrap it in an "if" block;
0
 
countrymeisterAuthor Commented:
carl_tawn:

Can you please give me a code example, what exactly do I have to do in my above logic
0
 
Carl TawnSystems and Integration DeveloperCommented:
Well it depends on what you want to do based on the confirm, but simplisticly:
Dim msgDesc As String = "if (confirm('No codes have been selected.\n\n Click OK to continue.')) DoSomething();"

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mribasuCommented:
you can do this another way 1st call client side function where you can check if  confirm  true then using __dopostback() come to server side and do somethig or false to  just return.
0
 
countrymeisterAuthor Commented:
carl_tawn:

I tried your example
Dim msgDesc As String = "if (confirm( 'No codes have been selected.\n\n Click OK to continue.')) DoSomething();"

I also added the following in my vb.net code behind
Private Function DoSomething() As Boolean
        Dim str As String = ""
        Return True
    End Function

I get a Jscript error ObjectExpected

I want to some how get to my server side code, so how do I implement the postback to some function or subroutine logic
0
 
Carl TawnSystems and Integration DeveloperCommented:
What is it you are getting confirmation for? Is it a button click, or part of another postback? If you want to trigger a postback then you'll probably need to use a hidden control in order to know what condition caused the postback.
0
 
countrymeisterAuthor Commented:
carl_tawn:

I have a submit button. On the click of that submit there iare checks to ensure data entered is valid.
Finally there is a check to see if the user has entered any codes (which is optional)

If no codes have been added, Need to display the confirm dialog box and if user clicks OK, then do rest of the processing.
0
 
Carl TawnSystems and Integration DeveloperCommented:
I'm guessing you are doing server-side checks rather than client-side?

If that is the case the i would add an invisible button to trigger the postback on confirmation:
<asp:Button ID="ConfirmButton" runat="server" style="display:none;" OnClick="ConfirmButton_Click" />

Then change your script to:

Dim msgDesc As String = "if (confirm('No codes have been selected.\n\n Click OK to continue.')) document.getElementById('" & Me.ConfirmButton.ClientID & "').click();"

Open in new window

0
 
countrymeisterAuthor Commented:
carl_tawn:

Thanks for your help, that worked.
0
 
countrymeisterAuthor Commented:
Thank you so much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now