John Mathison
John Mathison

Reputation: 912

ASP.NET Script after partial postback

I have a web page to modify a script that show the weather info of a certain city. In this page, users can change the city by loading a different script. This script is copied from a weather site, as a widget.

I have this line to show the weather:

 <asp:Literal ID="ltWeatherScript" runat="server" Text='<%# Eval("WeatherScript") %>'>
 </asp:Literal>

Where "WeatherScript" is the script that shows the weather.

The problem is when the page has a partial postback, the script doesn't work anymore until I reload the page.

The script could be, for example, this one:

script type="text/javascript" src="http://tiempo.meteored.com/wid_loader/50a0f88ef4aae65daacf31e7a4b1b0fe"

Do you know how to solve this?

Upvotes: 1

Views: 501

Answers (2)

Bernhard Hofmann
Bernhard Hofmann

Reputation: 10411

You need to get the script you're loading (WeatherScript) to execute again after a partial postback. Since the script is not a function, you'll need to create a function on the page that does the (shivers in horror) eval of the script you've loaded from their website. Then you'll need to invoke that function on page load and partial update.

What method are you using for partial postbacks? Update panels, jQuery/XUI AJAX call, etc? This will help me show you the code you need to add to invoke your new function when the partial postback completes.

Upvotes: 0

Nika G.
Nika G.

Reputation: 2384

I did checked the JS.

this lines are the only suspects to cause problem.

conte = document.getElementById('cont_50a0f88ef4aae65daacf31e7a4b1b0fe');
enlace = document.getElementById('h_50a0f88ef4aae65daacf31e7a4b1b0fe');
anchor = document.getElementById('a_50a0f88ef4aae65daacf31e7a4b1b0fe');

And you said The problem is when the page has a partial postback, the script doesn't work anymore. So the reason maybe that after postback control's IDs are changing. if you can post a markup that will help to diagnose the problem. as for solution, you have to specify the ClientId of the control. check the link Control.ClientID Property to get more info about this property and how to use it.

Upvotes: 0

Related Questions