This is a migrated thread and some comments may be shown as answers.

cannot call method get_selectedItem of null

2 Answers 112 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gotcha
Top achievements
Rank 1
Gotcha asked on 17 Nov 2011, 04:00 PM
Hi,

I'm having a problem ... and it may be related to the ID of the combo was renamed dynamically due to a partial post back.
I have a Page which has a Combo Box A showing my provinces, In this page I call a dynamic user control which is refreshed everytime Combo Box A is changed.

In my UC, I have another Combo Box B ( the problematic Combo) and on this UC ( Page_Init) I inject a JS in which i have the following snippet

string jsFunction =
@"
//Search TAB
//cmbSearchType - shows relevant input fields
function DefineView(sender, eventArgs) {
var comboSearch = $find('%%cmbSearchType%%');
//cmbSearch Section
switch (comboSearch.get_selectedItem().get_value()) {
[[MY CODE HERE]
}
}

function onPageLoad(){
$(document).ready(function(){
DefineView();
});
}";

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

string onLoadScript = @"Sys.Application.add_load(function(){ onPageLoad();})
";


ScriptManager.RegisterStartupScript(this, this.GetType(), "onLoadScript", onLoadScript, 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 A, it reload 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)

Thanks

2 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 22 Nov 2011, 02:27 PM
Hi Gotcha,

Let me suggest you take a look at this MSDN article - particularly at the ClientID Property section that you might find useful.

Regards,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Gotcha
Top achievements
Rank 1
answered on 23 Nov 2011, 05:11 PM
The problem was related to a dynamic control i was generating at each post back without assiging an ID... by specifying an ID , it kept the name the same,
Tags
ComboBox
Asked by
Gotcha
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Gotcha
Top achievements
Rank 1
Share this question
or