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

Home Posts Topics Members FAQ

Page.ParseContr ol drives me crazy

Hi,

I want to add dynamically controls to my aspx-Page by using the
Page.parseContr ol-method.

Page_Load contains this code:

str = "<asp:TextB ox runat='server' id='txtEingabe' TextMode='Singl eLine'
/><asp:RequiredF ieldValidator id='req' runat='server'
ControlToValida te='txtEingabe' >Bitte um eine
Eingabe</asp:RequiredFie ldValidator><as p:button runat='server' id='aspbtn'
text='OK'/>"

parsedCtrl = Page.ParseContr ol(str)

Dim i, anzahl As Integer

anzahl = parsedCtrl.Cont rols.Count

myLabel.InnerHt ml = "Number of Controls: " & anzahl.ToString & "<br>" '
output is: 3
myLabel.InnerHt ml &= "1: " & parsedCtrl.Cont rols(0).ToStrin g & "<br>" '
System.Web.UI.W ebControls.Text Box
myLabel.InnerHt ml &= "2: " & parsedCtrl.Cont rols(1).ToStrin g & "<br>" '
System.Web.UI.W ebControls.Requ iredFieldValida tor
myLabel.InnerHt ml &= "3: " & parsedCtrl.Cont rols(2).ToStrin g & "<br>" '
System.Web.UI.W ebControls.Butt on

myForm.Controls .Add(parsedCtrl .Controls(0)) ' OK
myForm.Controls .Add(parsedCtrl .Controls(1)) ' OK
'myForm.Control s.Add(parsedCtr l.Controls(2)) ' creates an error: index out
of bound !!!???
the problem is this line:
myForm.Controls .Add(parsedCtrl .Controls(2))

it creates the error "index out of bound",

but when I test it with: parsedCtrl.Cont rols(2).ToStrin g
I get the answer: "System.Web.UI. WebControls.But ton"

so the index is valid.

What is going on here?

When I omit this line:
myForm.Controls .Add(parsedCtrl .Controls(2))
I get a form with a inputbox and a button without the validator, which work
well.

I don't understand this. Do you?

Thank you

Matthias
ml@mlohrer.de
www.mlohrer.de

Nov 17 '05 #1
0 3030

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

Similar topics

7
3377
by: Oliver Andrich | last post by:
Hi everybody, I have to write a little skript, that reads some nasty xml formated files. "Nasty xml formated" means, we have a xml like syntax, no dtd, use html entities without declaration and so on. A task as I like it. My task looks like that... 1. read the data from the file. 2. get rid of the html entities 3. parse the stuff to extract the content of two tags.
7
2128
by: Jean-David Beyer | last post by:
I have six hard drives (4 SCSI and 2 EIDE) on my main machine with parts of a database on each drive. The main index is on one SCSI drive all to itself. The main data are on the other three SCSI drives. Small relations are on one EIDE drive, and the logfiles are on the other EIDE drive. When running the task, below, the rest of the machine is not doing much. I do not remember where I saw it, but somewhere I got the idea that the number...
1
3394
by: Matthias Lohrer | last post by:
Hi, I'm playing around with the possibilities of Page.ParseControl. I parse a string with an input-field and an RequiredFieldValidator-control. For testing the server-side validation I disable JavaScript and get this scenario: - When you enter a name, no warning appears, that's good! - When you don't enter a name, the warning appears, that's very good!
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" />
1
1373
by: DotNetWorks | last post by:
Does anyone know of a way to insert a directeve from the code behind? Background: I an creating a custom web control that wraps the IE Web control tab strip. The tab strip will still use the IE web control tab items but the tab strip container will be custom. So I will
4
1763
by: Adrijan Josic | last post by:
I have this idea, I need to know if it is possible and how. Let's say you have a content managed site with all its structure and content - everything in a relational database And a "blank" page that loads content from the database. This one single page would have to know what content is requested. Obviously this could be done by pageIDs in querystring and whatnot but this is not what I'd like Here's what I need The "blank" page lies...
1
1766
by: AlanJSmith | last post by:
Hi All, I am using ParseControl to load a formview contol from a string, some of the child controls are bound using Eval but these fail as Eval seems to have already been called within the parse leaving the databind expression blank causing an error to be raised on bind. If i use Bind instead of Eval i get the page back bound properly but of course i cant update the readonly fields so it fails on update.
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
8600
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,...
0
9156
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
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.