cannot call method get_selectedItem of null

3 posts, 0 answers
  1. Gotcha
    Gotcha avatar
    64 posts
    Member since:
    Sep 2009

    Posted 17 Nov 2011 Link to this post


    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()) {

    function onPageLoad(){

    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)

  2. Kalina
    Kalina avatar
    918 posts

    Posted 22 Nov 2011 Link to this post

    Hi Gotcha,

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

    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
  3. Gotcha
    Gotcha avatar
    64 posts
    Member since:
    Sep 2009

    Posted 23 Nov 2011 Link to this post

    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,
Back to Top