Question

I have a problem which I can't find a solution. I have a Parent page calling dynamically a default user control ( 6 different UC based on a selected item Combo X on the parent page). Within the UC, i inject (registerClientscript) a javascript which controls visibility within the UC based on a combo box. All UC has the same combo but the controls within this UC can vary.

The problem i am having is that on first load, the JS is generated correctly... but on change of Combo X from the parent, i trigger a partial refresh of the UC, which in turn re-register a new JS.

function DefineView(sender, eventArgs) { 
var comboSearch = $find('%%cmbSearchType%%'); 
//cmbSearch Section 
switch (comboSearch.get_selectedItem().get_value()) { 
[[MY CODE HERE]
} 
}

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "SearchVisibilityPPSA",jsFunction.Replace("%%cmbSearchType%%", cmbSearchType.ClientID),true); 

As you can see, I replace the ClientID, and on first load of the page, this is resolved correctly like ctl00_PrincipalPlaceHolder_ctl00_cmbSearchType but when I change Combo X, it reloads the user control, which in turn reload the script above. In the rendered HTML, The COmbo ID is renamed to ctl00_PrincipalPlaceHolder_ctl01_cmbSearchType (Note the subtle change in name from ct00 to ct01 ) In my debug, I saw this ClientID contain the new ID but somehow it is not replaced regenrated on the rendered html.

I guess my question is how do i force the JS to be re-rendered every time this UC is called? For some reason, it is always using the original rendered JS ( which is why it is working the first time)

Était-ce utile?

La solution

I think this is related to my dynamic control i was generating without assigining any id ... by forcing the id attribute, it kept it the same...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top