473,395 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help on register a client script using a Web Custom Control

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.IsClientScriptBlockRegister ed("MyPropertyScriptBlock"))
{
objPage.ClientScript.RegisterClientScriptBlock(cst ype,
"MyPropertyScriptBlock", sScript.ToString());
}
}
}

Tks,
Lourival

May 31 '06 #1
1 2117
lourivas,

That sounds like a NullReferenceException to me. Somewhere along the
line you are trying to call a method on a reference that is set to null.

Have you run this through the debugger and checked to see where it errs?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"lourivas" <lo*********@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
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.IsClientScriptBlockRegister ed("MyPropertyScriptBlock"))
{
objPage.ClientScript.RegisterClientScriptBlock(cst ype,
"MyPropertyScriptBlock", sScript.ToString());
}
}
}

Tks,
Lourival

May 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stangonline.com | last post by:
Ok, im familiar with typical troubleshooting of this type on problem, but I do not do any programming myself. Im hoping you guys can help me with an install problem that I am having. I have an...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
8
by: Lloyd Sheen | last post by:
I have a problem with persisting the state of a control. It has several properties that can be determined but there is no event to indicate when the property changes. A postback occurs when one...
8
by: Sue | last post by:
I have a datagrid populated with 6 visible read-only labels and several hidden fields. Below the datagrid, I have a table with various textboxes, dropdowns, etc. I've managed to decypher the...
0
by: Big Dave | last post by:
Good morning. I'm trying to register a client script block from a server control. I've put the line of code to register it in the render method, the onprerender event, I've overridden the...
8
by: Umut Tezduyar | last post by:
I know that, in asp.net 2.0, the assembly for the web site is splitted into pieces and each time you build it, it generates a random name for assembly. My question is, if i create a custom web...
1
by: lourivas | last post by:
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...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: Jonathan Wood | last post by:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages. The sample contains the following within the <headtag: <script type="text/javascript" src="flashobject.js"></script>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.