Solved

Call Client Script from Code behind ASP.NET

Posted on 2013-01-14
2
636 Views
Last Modified: 2013-01-16
Hello Experts,

I have a Javascript function, which gets called after the button event is processed everything on server. Since, I have lot of validations doing at client side, is it possible I can break the server code once the JS function is called and if no errors continue with the server side execution.Below code get called only after the button event is executed  on server.
 ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "Check('" + Msg+ "');", true);

Open in new window

I need to break the code on server side and execute my Client-Side function and then continue with the remaining server side code.I'm using AJAX Script manager and  button is doing asynchronous postback to the server using update panel.

Thanks,
ASPDEV
0
Comment
Question by:ASPDEV
2 Comments
 
LVL 21

Accepted Solution

by:
masterpass earned 500 total points
ID: 38776855
Just so that I understand you clearly, you want to do the following

user clicks a button

1. client side validation
2. button click in server side
3. go to client side again and perform validation
4. continue server side click event

If this is what you need, then technicaly the answer is no .. since we cannot break a server side operation in between and then return to the same operation

As a best practise, I would suggest that you do the server side validation before processing the event so that there is a very less possibility of errors.

But still if you need to acheive this, you can do something like this


user clicks a button (make sure you have a hidden button in form)

1. client side validation
2. button click event in server side
3. finish the function now and have a startup script so that it submits the form via the hidden button
4. write another server event for the hidden button and continue the event

Happy coding :)

PS: I would never do this approach since it is a not good. I would do a full client and server side valdiation and then process events.
0
 

Author Closing Comment

by:ASPDEV
ID: 38784874
Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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