473,395 Members | 1,516 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());
}
}
}

May 31 '06 #1
1 1345
What line of code is the exception coming from?

-Brock
http://staff.develop.com/ballen

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

Jun 1 '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...
1
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.