Asp.net RegisterClientScriptBlock

Posted on 2011-02-25
Medium Priority
Last Modified: 2012-05-11
I am calling this javascript from my asp.net. Can some one please let me know how i can catch whether user select Ok or cancel and do something?
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "showmessage", "confirm('" + strmsg + "');", true);
i want to know whether the use click Ok or cancel and do if Ok return and Cancel nothing
Question by:Angela4eva
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
  • 4
  • 3
LVL 28

Expert Comment

ID: 34982827
if(confirm(' + strmsg + ')){ MyFunctionOnSuccess() }

Author Comment

ID: 34983244
where should i put this line?
LVL 28

Expert Comment

ID: 34984219
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "showmessage", "if(confirm(' + strmsg + ')){ MyFunctionOnSuccess() };", true);
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!


Author Comment

ID: 34984395
I want to execute the next step if ok, otherwise(Cancel) I want to  return.
I do not want to call a function.
LVL 28

Accepted Solution

strickdd earned 750 total points
ID: 34984926
What is "the next step". You asked how to implement a confirm box and know whether the users selects OK or Cancel... that's what I gave you.

Author Comment

ID: 34985049
next step is next line after
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "showmessage", "if(confirm(' + strmsg + ')){ MyFunctionOnSuccess() };", true);
even the your script form does not work.

Assisted Solution

Tuyau2poil earned 750 total points
ID: 34993559
Well, you can't run client side code (for example javascript messagebox) and get immediate result in code behind because code behind is server side.
code behind need a postback to read client input, so code excution must stop and page reload before continuing.... impossible in this case to run code, ask something to user, and continue execution.
Only Javascript can do it, but javascript is not code behind....
I hope my explanation is not too tricky... I'm French and my english is in beta test !

Author Closing Comment

ID: 35195419

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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