Upload in an Usercontrol

F

Fernando Lopes

Hello.
I want to create a usercontrol for upload imagens.
So, I will put this usercontrol in a lot of pages in my application.
Probably will not work, because some form will not set with
enctype/multipart attribute.

How can I fix it?
Someone have any sample of usercontrol and upload?

Thanks
#Fernando Lopes
 
K

Karl Seguin

Fernando:
The only real solution I can think of is that you make use of a custom
server control for your form, ala:

public class SmartForm : HtmlForm {
private bool supportUpload;
public bool SupportUpload {
get { return supportUpload; }
set { supportUpload = value; }
}
protected override void Render(HtmlTextWriter writer) {
if (supportUpload) {
base.Method = "POST";
base.Enctype = " multipart/form-data";
}
base.Render(writer);
}
}

and can then use
<SomePrefix:SmartForm id="form1" runat="server" supportUpload="true">
...
</SomePrefix:SmartForm>

Karl
 
F

Fernando Lopes

Thanks Karls.
Just one thing. I must put this control in every page I put the upload
usercontrol?
This is correct?

Thanks again.
Fernando
 

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

Top