Solved

Call Client Script from Code behind ASP.NET

Posted on 2013-01-14
2
638 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

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!

Question has a verified solution.

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

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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