?
Solved

How to trap the OK cancel click for a client script

Posted on 2010-11-11
10
Medium Priority
?
335 Views
Last Modified: 2012-05-10

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
Comment
Question by:countrymeister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34110352
"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
 
LVL 1

Author Comment

by:countrymeister
ID: 34110367
carl_tawn:

Can you please give me a code example, what exactly do I have to do in my above logic
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34110401
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:mribasu
ID: 34110403
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34110506
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34110533
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34110569
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
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34110603
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
 
LVL 1

Author Comment

by:countrymeister
ID: 34110680
carl_tawn:

Thanks for your help, that worked.
0
 
LVL 1

Author Closing Comment

by:countrymeister
ID: 34110681
Thank you so much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question