I have a web application. On my page ive got this:
<div id="myDiv" runat="server" />
//and a button that will call a method to save my inputs
on code behind i have this :
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!this.IsPostBack)
{
.....
}
LoadForm(); // this will create a textbox with values inside it and a button called change
// into the div .
//when i click the button , it will create a fileupload control
//and add this control into the div
}
my problem is: when i first click the button change it will change the textbox and the button to an upload control, no problem with this one, but when i click the save button, on load the page will re-pass from the LoadForm() letting my page create a textbox, while i had changed it to an upload file, how can i solve this???
I dont know if i should add more details, or its clear, 开发者_如何转开发thanks in advanceprivate void LoadForm()
{
....
button.Click += new EventHandler(button_Click);
this.myDiv.Controls.Add(textBox);
this.myDiv.Controls.Add(button);
}
void button_Click(object sender, EventArgs e)
{
...
this.myDiv.Controls.Clear();
this.myDiv.Controls.Add(here will be the fileupload control);
}
The problem is that because you are creating the file upload dynamically, for it to show up again, it has to be re-added to the page. An option here would be to always have the control on the page, just toggle the visibility.
Put your LoadForm method in the if(!isPostback) condition as you don't want to create the textbox and button again while you click on Save button. Also you can access the dyncamically created fileUpload using the Request.Forms collections
精彩评论