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

javascript $find return null

1 Answer 98 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Gustavo
Top achievements
Rank 1
Gustavo asked on 19 Dec 2012, 11:53 AM
Hi Telerik Team, I have this webpart:

protected override void CreateChildControls()
{
      ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
      if (scriptManager == null)
      {
        scriptManager = new RadScriptManager();
        this.Page.Form.Controls.AddAt(0, scriptManager);
      }
}

protected override void OnLoad(EventArgs e)
{
      base.OnLoad(e);

      Panel panel = new Panel();
      panel.ID = "Panel1";
      this.Controls.Add(panel);   

      RadButton button = new RadButton();
      button.Height = 20;
      button.Width = 100;
      button.Text = "Click to update";
      button.ID = "ConfigureButton";
      button.OnClientClicked = "configureGauge";
      button.AutoPostBack = false;
      panel.Controls.Add(button); 

      radNumTextBox = new RadNumericTextBox();
      radNumTextBox.Height = 20;
      radNumTextBox.Width = 100;
      radNumTextBox.ID = "NewValueNumericBox";
      radNumTextBox.AllowOutOfRangeAutoCorrect = true;
      panel.Controls.Add(radNumTextBox);

      script = new Literal();
      script.ID = "scriptLiteral";
      script.Text = "<script type=\"text/javascript\">";
      script.Text += "function configureGauge() {";
      script.Text += "var value = $find('<%=NewValueNumericBox.ClientID %>');";
      script.Text += "alert(value);  }";
      script.Text += "</script>";
      this.Controls.Add(script);
}

When the configureGauge() function is called it returns null.
Do you know why this is happening?

Thanks,
Gustavo

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 20 Dec 2012, 08:35 AM
Hello,

You need to register the scripts through the ScriptManager, calling its RegisterStartupScripts() method and passing the script there.

Regards,
Iana Tsolova
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.
Tags
WebParts for SharePoint
Asked by
Gustavo
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or