Ask a Question related to ASP.NET General, Design and Development.
-
Matthias Lohrer #1
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
[email]ml@mlohrer.de[/email]
[url]www.mlohrer.de[/url]
Matthias Lohrer Guest
-
ParseControl
What approaches has anyone found that would allow for parsing of serverside events when using the Page.ParseControl method? I currently have the... -
Session Variable gets truncated and drives me crazy
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean... -
Using Validation Controls with Page.ParseControl
Hi, I'm playing around with the possibilities of Page.ParseControl. I parse a string with an input-field and an RequiredFieldValidator-control. ... -
Please tell me I'm crazy!!! - Reload page does not update textbox values.
Scenario: 1. I dynamically generate a form (using server-side code) with numerous text boxes that are populated with values from a database. ... -
Appropriate hdparm use for modern IDE drives and CD-R/RW/DVD drives?
In http://tinyurl.com/hran (alt.os.linux and comp.os.linux.setup only -- sorry, forgot to add alt.comp.periphs.mainboard.soyo to Newsgroups: in...



Reply With Quote

