Solved

Call Client Script from Code behind ASP.NET

Posted on 2013-01-14
2
634 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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now