[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 652
  • Last Modified:

Call Client Script from Code behind ASP.NET

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
ASPDEV
Asked:
ASPDEV
1 Solution
 
masterpassCommented:
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
 
ASPDEVAuthor Commented:
Thanks.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now