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 18259 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.

Latest discussions

  • No posts to display.