Cédric Boivin
Cédric Boivin

Reputation: 11361

Call javascript code afer postback from an update panel

I read tis post

but my problem still there. I try to execute a javascript multiple time on post back, and the script only execute the first time the page load.

To make sure the script is register after each post back i use a guid for the javascript key name.

var xyz = DateTime.Now.ToLongTimeString();
  string script = @"BrokerCustomValue.value='" + CustomValueToBrokerListSerialized + "';alert('" + xyz + "');";
  ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);

I need to precise that my post back event fire after a click on a link button in an update panel. If i put my link butto directly in the page it's working

Upvotes: 1

Views: 6965

Answers (1)

Cédric Boivin
Cédric Boivin

Reputation: 11361

I found the solutions.

When you use an update panel and whant register script, you need to user updatePanel, and updatepanel type in param of the registerstartupscript

like this :

var xyz = DateTime.Now.ToLongTimeString();
  string script = @"BrokerCustomValue.value='" + CustomValueToBrokerListSerialized + "';alert('" + xyz + "');";
  ScriptManager.RegisterStartupScript(_updPanel, _updPanel.GetType(), Guid.NewGuid().ToString(), script, true);

Upvotes: 5

Related Questions