A Strange Problem with ParseControl Method
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcontrolscs' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

khanmirza hamed
Hi all,

I have a problem with ParseControl method.
When I use it to parse a string to control it throws
an exception:
A NULL value was referenced
I tried the MSDN example and I got the same result.
My code is very simple. In a PageLoad of a webform I
have written:
-----------------------------------
private void Page_Load(object sender,
System.EventArgs e){
         Button b1= (Button) ParseControl("<asp:button
runat=\"server\"/>");
         b1.Text = "Submit";
         Controls.Add(b1);
}
------------------------------------

Please help me:(
with regards

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

Reply to this message...
 
    
Brian Bilbro (VIP)
This is strange. I don't get a null reference. I get invalid cast
exception.

I even tried to cut-and-paste the sample at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebUITemplateControlClassParseControlTopic.asp

but still get an invalid cast exception. I tried this code both in a
code-behind and in a script tag on the .aspx page.

--
Brian

----- Original Message -----
From: "khanmirza hamed" <Click here to reveal e-mail address>
To: "aspngcontrolscs" <Click here to reveal e-mail address>
Sent: Saturday, April 20, 2002 7:53 AM
Subject: [aspngcontrolscs] A Strange Problem with ParseControl Method

[Original message clipped]

Reply to this message...
 
    
Paul D. Murphy
I'm not 100% on this, but I think this method is really only used for
advanced control development and should only be used in the pre-init
stages while the control tree is being built. I could be dead wrong, but
I think that's the case.

Paul

-----Original Message-----
From: khanmirza hamed [mailto:Click here to reveal e-mail address]=20
Sent: Saturday, April 20, 2002 7:53 AM
To: aspngcontrolscs
Subject: [aspngcontrolscs] A Strange Problem with ParseControl Method

Hi all,

I have a problem with ParseControl method.=20
When I use it to parse a string to control it throws
an exception:
A NULL value was referenced
I tried the MSDN example and I got the same result.
My code is very simple. In a PageLoad of a webform I
have written:
-----------------------------------
private void Page_Load(object sender,
System.EventArgs e){
         Button b1=3D (Button) ParseControl("<asp:button
runat=3D\"server\"/>");
         b1.Text =3D "Submit";
         Controls.Add(b1);
}=20
------------------------------------
=20
Please help me:(
with regards

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

| [aspngcontrolscs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngcontrolscs.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Brian Bilbro (VIP)
If that's the case, then this sample code should be correted:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebUITemplateControlClassParseControlTopic.asp

I also tried the following:
* Tried using the ParseControl in Init and it still throws an invalid cast
exception.
* Tried using the ParseControl in the Page constructor (I assume this is
what you mean by pre-init) and it still thorws an invalid cast exception.

--
Brian

----- Original Message -----
From: "Paul D. Murphy" <Click here to reveal e-mail address>
To: "aspngcontrolscs" <Click here to reveal e-mail address>
Sent: Saturday, April 20, 2002 3:27 PM
Subject: [aspngcontrolscs] RE: A Strange Problem with ParseControl Method

I'm not 100% on this, but I think this method is really only used for
advanced control development and should only be used in the pre-init
stages while the control tree is being built. I could be dead wrong, but
I think that's the case.

Paul

-----Original Message-----
From: khanmirza hamed [mailto:Click here to reveal e-mail address]
Sent: Saturday, April 20, 2002 7:53 AM
To: aspngcontrolscs
Subject: [aspngcontrolscs] A Strange Problem with ParseControl Method

Hi all,

I have a problem with ParseControl method.
When I use it to parse a string to control it throws
an exception:
A NULL value was referenced
I tried the MSDN example and I got the same result.
My code is very simple. In a PageLoad of a webform I
have written:
-----------------------------------
private void Page_Load(object sender,
System.EventArgs e){
Button b1= (Button) ParseControl("<asp:button
runat=\"server\"/>");
b1.Text = "Submit";
Controls.Add(b1);
}
------------------------------------

Please help me:(
with regards

__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/

| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [aspngcontrolscs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcontrolscs.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
 
System.EventArgs




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com