473,395 Members | 1,497 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,395 software developers and data experts.

Page.ParseControl drives me crazy

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
Eingabe</asp:RequiredFieldValidator><asp:button runat='server' id='aspbtn'
text='OK'/>"

parsedCtrl = Page.ParseControl(str)

Dim i, anzahl As Integer

anzahl = parsedCtrl.Controls.Count

myLabel.InnerHtml = "Number of Controls: " & anzahl.ToString & "<br>" '
output is: 3
myLabel.InnerHtml &= "1: " & parsedCtrl.Controls(0).ToString & "<br>" '
System.Web.UI.WebControls.TextBox
myLabel.InnerHtml &= "2: " & parsedCtrl.Controls(1).ToString & "<br>" '
System.Web.UI.WebControls.RequiredFieldValidator
myLabel.InnerHtml &= "3: " & parsedCtrl.Controls(2).ToString & "<br>" '
System.Web.UI.WebControls.Button

myForm.Controls.Add(parsedCtrl.Controls(0)) ' OK
myForm.Controls.Add(parsedCtrl.Controls(1)) ' OK
'myForm.Controls.Add(parsedCtrl.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.Controls(2).ToString
I get the answer: "System.Web.UI.WebControls.Button"

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 3018

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

Similar topics

7
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...
7
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...
1
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...
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'...
1
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...
4
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...
1
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...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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...

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.