On the project I am currently working on, the entire department uses the same Portal for hosting the different applications. That's great in that it promotes reusability, a common look and feel, quicker development and a central place for users to get all related information. I could go on and on, but I won't because there's one downside: flexibility.
We had a request from a user to allow uploading some files. Simple enough task, except our web pages all inherit from the same base web page, and there's no flexibility allowed in what we can do with that page. So, I had a dilemma. I had to give the user's the ability to upload files, but I couldn't change the base page that I HAD to use.
Simple enough, I would do a search for the form tag, and change the EncType dynamically! And here's how I did it...
Once again, I passed in the Page reference, because this sits in a common library. If you don't want to do that, just use the current Page reference. The other thing you might want to do is change the “form1“ reference as a parameter to make it more flexibility. At the time I wrote this, I knew it would never change, so I just left it..
public static void ChangePortalEncType(Page page)
{
HtmlForm form1;
if (page.FindControl("form1") != null)
form1 = (HtmlForm) page.FindControl("form1");
if (form1.Attributes["enctype"] != null)
if (form1.Attributes["enctype"] != "multipart/form-data")
form1.Attributes["enctype"] = "multipart/form-data";
}
else
form1.Attributes.Add("enctype","multipart/form-data");
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, © Copyright 2010
E-mail