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