Easiest way to update client side javascript variable during ASP.NET AJAX postback to UpdatePanel?

If I want to insert a global reach array variable in javascript on the client side of the page during full-text postback, I can use:

this.Page.ClientScript.RegisterArrayDeclaration("WorkCalendar", "\"" + date.ToShortDateString() + "\"");

to declare and populate a javascript array on the client side of the page. Nice and simple.

But I want to do the same with async postback from UpdatePanel.

The closest I can guess is to create a .js file that just contains a var declaration, update the file during async postback, and then use it ScriptManagerProxy.Scripts.Addto add the .js file to the global area of ​​the page.

Is there anything simpler? Notify him wrong?

+3
source share
3 answers

You can also update the hidden label inside the update panel, which will allow you to write out any javascript you like. I suggest using web services or even page methods to get the data you need, instead of using the update panels.

Example: myLabel.Text = "...."; ... put your logic in this or you can add [WebMethod] to any public method of a static page and directly return data.

0
source

Use the static method System.Web.UI.ScriptManager.AddStartupScript ()

The script will work on all full and partial postbacks.

+3
source

. ScriptManager.RegisterStartupScript - . .

+2

Source: https://habr.com/ru/post/1697147/


All Articles