473,396 Members | 2,154 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,396 software developers and data experts.

More ParseControl()

I am playing around with ParseControl(), and I have a question. First here
is the code I am using:

Control MyButton1 = Page.ParseControl("<asp:button id='MyButton'
text='Click here!' runat='server' />");
Form1.Controls.Add(MyButton1);

This adds the button to the form; however, I cannot access the button using
it's ID (and I have declared it in the class). I can, however, access it
through the Controls[] collection of Form1. The drawback is that I cannot
access any of the Button class' properties. I have tried casting it:

Button MyButton2 = (Button) MyButton1;

But I get an invalid cast error at runtime.

My question is this: Is there a way where I can access the control, as a
Button, that was parsed through ParseControl other than the Controls[]
collection of its parent?

Thanks.
Nov 18 '05 #1
1 1625
I found the solution. It seems that I had to cast using the FindControl()
method:

Button MyButton1 = (Button)Form1.FindControl("MyButton");

"Jeremy McPeak" <http://www.wdonline.com/contact.aspx> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
I am playing around with ParseControl(), and I have a question. First here is the code I am using:

Control MyButton1 = Page.ParseControl("<asp:button id='MyButton'
text='Click here!' runat='server' />");
Form1.Controls.Add(MyButton1);

This adds the button to the form; however, I cannot access the button using it's ID (and I have declared it in the class). I can, however, access it
through the Controls[] collection of Form1. The drawback is that I cannot
access any of the Button class' properties. I have tried casting it:

Button MyButton2 = (Button) MyButton1;

But I get an invalid cast error at runtime.

My question is this: Is there a way where I can access the control, as a
Button, that was parsed through ParseControl other than the Controls[]
collection of its parent?

Thanks.

Nov 18 '05 #2

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

Similar topics

0
by: Matthias Lohrer | last post by:
Hi, I'm playing around with the possibilities of Page.ParseControl. Thanks to Kirk Allen Evans I got my example running (Posting Juli, 17, "Re: Generating ASP.NET-Controls with XSLT...
0
by: Matthias Lohrer | last post by:
Hi, I want to add dynamically controls to my aspx-Page by using the Page.parseControl-method. Page_Load contains this code: str = "<asp:TextBox runat='server' id='txtEingabe'...
0
by: Chris Simeone | last post by:
Hello, I'm having problems with the ParseControl() method creating unexpected output which I think is preventing events from firing. My code is based on this MSDN article:...
1
by: Jeremy McPeak | last post by:
Good morning. I am having a problem with the TemplateControl.ParseControl() method. It does parse the string into a control; however, added attributes are left out of the parsing and make it to...
2
by: Chris Simeone | last post by:
When I use ParseControl in a C# code behind to create a button... Control c3 = ParseControl("<asp:button id='Button3' text='Btn3' oncommand='OnButton' commandname='Btn' commandargument='b3'...
0
by: PB | last post by:
According to the documentation, ParseControl returns a parsed control from an input string. The documentation seems to assume that *one* control will be parsed from the string. My implementation...
0
by: Fox | last post by:
Greetings, How can i parse inline code? I have the following code: System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<asp:TextBox id=\"myControl\" runat=\"server\"...
0
by: Dave | last post by:
Hi, I have a very simple page where i am using Page.ParseControl to create a datagrid control. When i try to run the DataBind method i get various errors. The code for the datagrid is as...
1
by: Jordan S. | last post by:
Using .NET 3.5, I'm wondering how to get a control's specific type (e.g,. "Button" and not simply "Control") after the control is inserted into a control hierarchy - when ParseControl is used. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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...
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...
0
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...

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.