Help on register a client script using a Web Custom Control

L

lourivas

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());
}
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top