473,698 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More ParseControl()

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

Control MyButton1 = Page.ParseContr ol("<asp:butto n 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 1638
I found the solution. It seems that I had to cast using the FindControl()
method:

Button MyButton1 = (Button)Form1.F indControl("MyB utton");

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

Control MyButton1 = Page.ParseContr ol("<asp:butto n 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
2267
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 possible?"). But looking deeper I run into a problem: Kirk said, that "validation works as expected", but in my experience it works only to a certain degree "as expected".
0
3031
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' TextMode='SingleLine' /><asp:RequiredFieldValidator id='req' runat='server' ControlToValidate='txtEingabe'>Bitte um eine
0
1187
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/ frlrfsystemwebuitemplatecontrolclassparsecontrolto pic.asp
1
1921
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 the final HTML code. For example: ParseControl("<asp:button OnClick="Btn_Click" text='Click here!' runat='server' />"); Becomes this HTML:
2
1487
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' runat='server' />"); The HTML that's rendered looks like this... <input type="submit" name="Button3" value="Btn3" id="Button3" oncommand="OnButton" />
0
1407
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 will require an unknown number of controls (always at least one) to be parsed from the string... after which I inject the resulting HTML into a PlaceHolder control (see code below). In my testing, it appears that ParseControl will successfully...
0
1138
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\" />"); sb.Append("<%= \"Hello!\"%>");
0
1281
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 follows and is fired on OnInit string grid = "<asp:DataGrid ID=\"grid2\" runat=\"server \"><Columns><asp:TemplateColumn><ItemTemplate><asp:LinkButton ID= \"link1\" runat=\"server\"><%# DataBinder.Eval(Container.DataItem,
1
1819
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. For example, I have the following code: string str = "<table border=1><tr><td>Hello World</td></tr><tr><td><asp:Button ID=\"TestButton\" onclick=\"b_Click\" runat=\"server\" Text=\"Button\" /></td></tr><tr><td>Goodbye...
0
8601
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8892
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.