Hi all,
In one of my projects, I have coded like this.
code behind>>>>>>>>>>>>>>>>>>>
protected void Button2_Click(object sender, EventArgs e)
{
if (fupLogo.HasFile)
{
string fileFormat = fupLogo.PostedFile.ContentType;
Label1.Text = fupLogo.PostedFile.ContentType;
if (string.Compare(fileFormat, "image/jpeg", true) == 0 ||
string.Compare(fileFormat, "image/png", true) == 0 ||
string.Compare(fileFormat, "image/gif", true) == 0)
{
Label1.Text += "file format supported
";
}
else
{
Label1.Text +="file format not supported
";
}
}
else
{
Label1.Text += "file not exist
";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
fupLogo.Visible = true;
Button2.Visible=true;
}
this behaves like on page load it shows a button then the onclick of the
button it shows a fileupload and upload button
Expected: when i cliks upload button after selecting any file
ouput must be “file format supported/not suported”
Actual: but the output is “file not exist”.
As a solution I just found these,
Use style=”display:none” instead of Visible=”False”. In this case PostBackTrigger for Button2 works correctly.
Example:
..aspx file
asp:FileUpload ID="fupLogo" runat="server" style="display:none"
asp:Button ID="Button2" runat="server" Text="Upload"
OnClick="Button2_Click" style="display:none"
..cs file
protected void Button1_Click(object sender, EventArgs e)
{
fupLogo.Style.Remove("display");
Button2.Style.Remove("display");
}