I have this code in my aspx file. The code that is in $(document).ready function
should be executed from the code behind file. When the user is in certain role then only
this code should be executed.How can I do that?
You can create a method say initData in javascript, put all document.ready code in it and call it from server side using Page.RegisterStartupScript in user
role condition.
Ok.. I created initData function
function initData() {
.......
}
copied all the code from document.ready and pasted into initData. Need little more help on calling this function from codebehind now..
The example in the link shows to call a script created in codebehind, but how do I call this function?
remember you don't call javascript from the server. you write javascript to the html response that will be executed when the browser loads the response (after the server page lifecycle).
detemine how you would code the html/javascript by hand to do what you want when the page loaded into the browser. then have the server render the proper javascript. register script block places the javascript just after the <form> tag, register startup
script places the javascript code just before the </form> tag.
nissan
Participant
1065 Points
618 Posts
Run jquery from code-behind
Jan 07, 2013 07:39 PM|LINK
Hello,
I have this code in my aspx file. The code that is in $(document).ready function
should be executed from the code behind file. When the user is in certain role then only
this code should be executed.How can I do that?
<script language="javascript" type="text/javascript"> $(document).ready(function () { $('#employeeResponseRadioDiv input').click(function () { SetStep15to18DataVisibility(); }); $('#step17Table input').click(function () { SetStep15to18DataVisibility(); }); $("#<%= NotificationDateBox.ClientID %>").inputmask("m/d/y"); $("#<%= AgreedCorrectionDateBox.ClientID %>").inputmask("m/d/y"); $("#<%= AdditionalExtensionDateBox.ClientID %>").inputmask("m/d/y"); $("#<%= ActualCorrectionDateBox.ClientID %>").inputmask("m/d/y"); $("#<%= NotificationDateBox.ClientID %>").datepicker({ minDate: new Date(2009, 0, 1), maxDate: '+0', showOn: 'button', buttonImageOnly: true, buttonImage: '../Images/Calendar_scheduleHS.png' }); $("#<%= AgreedCorrectionDateBox.ClientID %>").datepicker({ minDate: new Date(2009, 0, 1), showOn: 'button', buttonImageOnly: true, buttonImage: '../Images/Calendar_scheduleHS.png' }); $("#<%= AdditionalExtensionDateBox.ClientID %>").datepicker({ minDate: new Date(2009, 0, 1), showOn: 'button', buttonImageOnly: true, buttonImage: '../Images/Calendar_scheduleHS.png' }); $("#<%= ActualCorrectionDateBox.ClientID %>").datepicker({ minDate: new Date(2009, 0, 1), maxDate: '+0', showOn: 'button', buttonImageOnly: true, buttonImage: '../Images/Calendar_scheduleHS.png' }); SetStep15to18DataVisibility(); }); function SetStep15to18DataVisibility() { EnableSomeControls(); } function EnableSomeControls() { //Call more functions } </script>urenjoy
Star
12149 Points
1823 Posts
Re: Run jquery from code-behind
Jan 08, 2013 09:34 AM|LINK
You can create a method say initData in javascript, put all document.ready code in it and call it from server side using Page.RegisterStartupScript in user role condition.
nissan
Participant
1065 Points
618 Posts
Re: Run jquery from code-behind
Jan 08, 2013 02:29 PM|LINK
Ok.. I created initData function function initData() { ....... } copied all the code from document.ready and pasted into initData. Need little more help on calling this function from codebehind now.. The example in the link shows to call a script created in codebehind, but how do I call this function?bruce (sqlwo...
All-Star
36822 Points
5441 Posts
Re: Run jquery from code-behind
Jan 08, 2013 03:44 PM|LINK
remember you don't call javascript from the server. you write javascript to the html response that will be executed when the browser loads the response (after the server page lifecycle).
detemine how you would code the html/javascript by hand to do what you want when the page loaded into the browser. then have the server render the proper javascript. register script block places the javascript just after the <form> tag, register startup script places the javascript code just before the </form> tag.
asteranup
All-Star
30184 Points
4906 Posts
Re: Run jquery from code-behind
Jan 09, 2013 02:09 AM|LINK
Hi,
You can use window.onload like below-
http://delicious.com/anupdg/onload+window
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog