473,548 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Behav ior")]
[DefaultValue(fa lse)]
public bool MyProperty
{
get
{
object o = ViewState["MyProperty "];
return (o == null) ? false : (bool)o;
}
set
{
m_bMyProperty = value;
ViewState["MyProperty "] = value;
CreateScriptOnC lient();
}
}

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

private void CreateScriptOnC lient()
{

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

Type cstype = this.GetType();
Page objPage = (Page)HttpConte xt.Current.Hand ler;
if
(!objPage.Clien tScript.IsClien tScriptBlockReg istered("MyProp ertyScriptBlock "))
{
objPage.ClientS cript.RegisterC lientScriptBloc k(cstype,
"MyPropertyScri ptBlock", sScript.ToStrin g());
}
}
}

Tks,
Lourival

May 31 '06 #1
1 2128
lourivas,

That sounds like a NullReferenceEx ception 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.co m

"lourivas" <lo*********@gm ail.com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.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("Behav ior")]
[DefaultValue(fa lse)]
public bool MyProperty
{
get
{
object o = ViewState["MyProperty "];
return (o == null) ? false : (bool)o;
}
set
{
m_bMyProperty = value;
ViewState["MyProperty "] = value;
CreateScriptOnC lient();
}
}

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

private void CreateScriptOnC lient()
{

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

Type cstype = this.GetType();
Page objPage = (Page)HttpConte xt.Current.Hand ler;
if
(!objPage.Clien tScript.IsClien tScriptBlockReg istered("MyProp ertyScriptBlock "))
{
objPage.ClientS cript.RegisterC lientScriptBloc k(cstype,
"MyPropertyScri ptBlock", sScript.ToStrin g());
}
}
}

Tks,
Lourival

May 31 '06 #2

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

Similar topics

3
15060
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 application that fails to register 2 .ocx files during installation. The OS is Windows Server 2003 running as a terminal server. I have since tried...
8
5456
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I...
8
1255
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 of a array of buttons is clicked. On the click new information will be displayed but I need to save information from the control (which I cannot...
8
3039
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 client-side coding needed for the user to click a "select" button (HTMLButton) in column 0 of the datagrid and have the table objects auto-fill with...
0
1245
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 pre-render method, the controls init event, everything, but I still can't get it to work. When I debug, I can step through to that line, but it's still not...
8
6331
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 control under the App_Code folder, how can i add a register tag on a page. <%@ Register TagPrefix="ABC" Namespace="ABC.Foo"...
1
1353
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 "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:
0
5536
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
4
1678
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> <script type="text/javascript"> // <!.indexOf('='); if( pos == -1 ) { continue; // Look for "name=value"
0
7512
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.