Asp.Net Page Postback from Javascript

If you need to do page postback from javascript, this one is for you…
Today I came across situation where we were using Jquery calendar but we needed postback as soon as date is selected by user.

Step 1- Bind Javascript function to onselect event of Jquery calendar

$(“#mydatepicker”).datepicker({
onSelect: function(dateText, inst) {
_doPostBack(“buttonidoranyvalue”,””);
}
});

Above will make sure page is post back as soon as date is selected by user.
first parameter is eventtarget, second paramerter is eventargument.
Same can be used in any java scripts functions

Step 2 – Check Event Target in Request.Forms parameters and do whatever you want man  like below

if(Request.Form.Params.Get(“_EVENTTARGET”) == “buttonidoranyvalue”) {
//do whatever you want 
}

Hope this helps…Happy Coding!!!!

(Visited 15 times, 1 visits today)