Help on register a client script using a Web Custom Control

Discussion in 'ASP .Net' started by lourivas, May 31, 2006.

  1. lourivas

    lourivas Guest

    Hi,
    I create a class with a property called MyProperty that needs to
    register a client script if the value is set to true. When i change the
    property value to true i always receive a message "Property value is
    not valid/Object reference not set to an instance of an object". I'm
    using VS 2005. What i'm missing?

    see:

    [Category("Behavior")]
    [DefaultValue(false)]
    public bool MyProperty
    {
    get
    {
    object o = ViewState["MyProperty"];
    return (o == null) ? false : (bool)o;
    }
    set
    {
    m_bMyProperty = value;
    ViewState["MyProperty"] = value;
    CreateScriptOnClient();
    }
    }

    On the CreateScriptOnClient method i try to verify if the script block
    is already registered and if not i register using:

    private void CreateScriptOnClient()
    {

    StringBuilder sScript = new StringBuilder();
    if (m_bMyProperty == true)
    {
    sScript.AppendLine("<SCRIPT language=javascript>");
    sScript.AppendLine("var digitacoes; var texto; var enter; var
    tab; ");
    ... MORE Script....
    sScript.AppendLine("</script>");

    Type cstype = this.GetType();
    Page objPage = (Page)HttpContext.Current.Handler;
    if
    (!objPage.ClientScript.IsClientScriptBlockRegistered("MyPropertyScriptBlock"))
    {
    objPage.ClientScript.RegisterClientScriptBlock(cstype,
    "MyPropertyScriptBlock", sScript.ToString());
    }
    }
    }
     
    lourivas, May 31, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    5
    Views:
    1,056
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  2. Nathan Sokalski
    Replies:
    4
    Views:
    321
    Nathan Sokalski
    Dec 21, 2006
  3. Earl Teigrob

    Where to Register Client Scripts in Custom Control?

    Earl Teigrob, Dec 30, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    132
    Alessandro Zifiglio
    Dec 30, 2003
  4. Replies:
    1
    Views:
    329
    Teemu Keiski
    Jul 8, 2005
  5. Nathan Sokalski
    Replies:
    4
    Views:
    359
    Nathan Sokalski
    Dec 21, 2006
Loading...

Share This Page