NiteTrip
NiteTrip

Reputation: 198

How to call a javascript function from code-behind of a partially loaded aspx page

I have an asp.net application and I use jquery's .load function to load content into a specific div like so:

 $('#pnl').load('/Panel.aspx #panel', loadLogs());

From the Panel.aspx page I populate some dropdowns in the code-behind load event, and from there I have some javascript functions(in a separate javascript file) that display text files based on the content of the dropdowns, which is controlled by the change events on the dropdowns. I am having an issue of when the page is loaded, the dropdowns are populated but I need to actually click on one of them to get the files to display. I have tried to call the javascript functions from the load event of Panel.aspx with Page.ClientScript.RegisterClientScriptBlock and they are not firing. I have also tried firing it from window.onload or $(document).ready from the javascript file and it is still not working.

Any suggestions for how I can get this done?

Upvotes: 0

Views: 386

Answers (1)

Dgan
Dgan

Reputation: 10285

try something like this

If you Used Update Panels Then You can Use:

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "javascriptFunction();", true);

Other Wise You can Use

ClientScript.RegisterStartupScript
        (GetType(),Guid.NewGuid().ToString(), "javascriptFunction();",true);

Upvotes: 1

Related Questions