Programatically add a HtmlInputFile control?

R

Rob Meade

Hi all,

I've got some code here that builds a page dynamically, ie, added a table,
rows, cells, controls in the cells and so on...

Everything has gone fine until now, I need to add a 'File Input' box (ie,
the HTML <input type="file"> etc), I've got this:

Dim txtFile as HtmlInputFile

txtFile = New HtmlInputFile
txtFile.ID = "txtFile"

Its currently not even appearing on the page, so I tried to do this around
the opposite way, I added one via the IDE in VS, I changed its runat to
server, one thing I noticed here was that it had a 'class' property, but
when I try to access this via the code approach above, after I've typed
txtFile. the intellisense doesn't give me a 'class' option...wondering now
if maybe I'm getting confused with it all..

I basically want to add the file input control via code...if anyone can give
me some pointers I'd be grateful.

Regards

Rob
 
R

Rob Meade

"Rob Meade" embarrassinly realises...

ok - so I'd missed the line of code need to add my table row to the table -
doh!..

Ok - so its on the page now - however, I cant seem to set the 'cssclass' for
it - it doesn't have it as a property in the intellisense..

Any ideas?

Rob
 
B

Bryant Hankins

You need to use the Controls.Add method to add your newly created control to
the Page controls collection like so:
Dim txtFile as HtmlInputFile

txtFile = New HtmlInputFile
txtFile.ID = "txtFile"
Controls.Add(txtFile)
 
A

ASP.Confused

Also (not to insult your knowledge of programming or anything), make sure
you set the Visible property before adding the control:

txtFile.Visible = true

If you want to play with the styles of the control, try looking for CSSStyle
or CSSClass instead of the class property (I think.)
 
R

Rob Meade

...
You need to use the Controls.Add method to add your newly created control to
the Page controls collection like so:

Hi Bryant, thanks for your reply.

As per my other post I managed to get it on the screen, I'd added the
control to the cell, and the cell to the row, just not the row to the
table - lol...daft eh...

That aside, if you know how to set the cssclass for this object that would
be handy :)

Regards

Rob
 
R

Rob Meade

...
Also (not to insult your knowledge of programming or anything),

hehe, cheeky monkey :eek:p
make sure you set the Visible property before adding the control:

txtFile.Visible = true

yep, I saw that property and had set it to true to be on the safe side,
looks like thats probably the default as having removed it, it stills shows
without problem.
If you want to play with the styles of the control, try looking for CSSStyle
or CSSClass instead of the class property (I think.)

thats what I was looking for, typically you get a 'class' or a 'cssClass'
property (as you know) - but neither of these are available...the only one
that looks 'possible' is 'style' - but its not doing what one would
expect...

Regards

Rob
 
B

Bryant Hankins

If you are using an HTMLControl then you'd get to the css class by going
through the generic attributes collection:

File1.Attributes("class") = "mycssclass"
 
R

Rob Meade

The attributes thing worked a treat - funny that there's so many ways to
achieve the same thing etc, makes it that little bit harder for the newbie
:)

Thanks though people - your help is appreciated..

Regards

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top