1

I have the below static method... i want to change the server side label's value from this method..

Public Static void CallFromJquery()
{
Default1 page = (Default1)HttpContext.Current.CurrentHandler;
page.Label1.Text = "Hello";
}

Please let me know how this can done.. thanks in advance :)

Regards, Kalyan

1 Answers1

0

You can't call server-side code with jQuery. You can call web services, but they won't affect your page, or you could load an aspx page into a div and that could return script to modify the label, but you can't just call a server method like you've asked.

If you explain a little more about why you want to do it then there may be a workround. For example, you can change the text of the label with jQuery, but it must all be done client-side. For example...

$("#ctl00_MainContent_Label1").text("Hello world");

that's likely to be the correct code to change your label text, but there are ways to ensure that you get the correct ID.

If you're not just looking for an answer to "does this work", then give us more info and we can probably help.

Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67
  • i have a timer which should trigger a non static method to fire on its expiry.. so i am using jquery Postmethods to call the static c# method.. so in turn i have called the non static method from this static method.. am i clear or do you need more explanation?? – Kalyan Chakravarthy S Feb 09 '12 at 11:58
  • The timer will cause a postback, so the page will simply reload. Can you not just change the value of the label then? If you need to pass a value from the client then just put it in a hidden field. – Reinstate Monica Cellio Feb 09 '12 at 13:02