Sunday, 20 January 2013 13:56

how to register and run jquery from code behind file

Written by 
Rate this item
(1 Vote)

for purposes you may want to register and run jquery
functions from code behind file.

for this - write the two methods first -

private string getjQueryCode(string jsCodetoRun)
{
StringBuilder stringb = new StringBuilder();
stringb.AppendLine(" function pageLoad() {");
stringb.AppendLine(jqCodetoRun);
stringb.AppendLine(" };");

return stringb.ToString();
}
private void runjQueryCode(string jsCodetoRun)
{
ScriptManager requestS = ScriptManager.GetCurrent(Page);
if (requestS != null && requestS.IsInAsyncPostBack)
{
ScriptManager.RegisterStartupScript(this, typeof(Page),
Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), true);
}
else
{
Page.ClientScript.RegisterStartupScript(typeof(Page),
Guid.NewGuid().ToString(), getjQueryCode(jsCodetoRun), true);
}
}

from the coding you understand how scripts are regsitered.then
to run any jquery functions you will call above methods as follows-

runjQueryCode("$(function () {$('.slider_callout').val('" + tempo / 10 + "');
var bvalue = $('.bavalue').val();........ });");

you can run any jquery codes above

If you have questions about this post or any topics, post your questions in
discussions/forum in this website, you will get your answer

Read 11341 times Last modified on Monday, 19 August 2013 14:38
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

2 comments

  • Comment Link Tuesday, 23 July 2013 12:15 posted by Bilkicell

    =

  • Comment Link Monday, 22 July 2013 10:12 posted by PHI

    Hiya, You have done a very good career. Let me definitely stumbleupon it and then for this component propose so that you can friends and neighbors. I am sure they shall be taken advantage of this fabulous website.

Login to post comments