By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,482 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

FileUpload and update panel

P: n/a


i have coded like this
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:Label ID="Label1" runat="server">
<asp:FileUpload ID="fupLogo" runat="server" Visible="False">

<asp:Button ID="Button2" runat="server" Text="Upload"
OnClick="Button2_Click" Visible="False" />

</asp:FileUpload><asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="show Uploader " />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button2">
</asp:PostBackTrigger>
</Triggers>
</asp:UpdatePanel>
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<br/>";
}
else
{
Label1.Text +="file format not supported<br/>";
}
}
else
{
Label1.Text += "file not exist<br/>";
}
}

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".
Jul 17 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 17 , 10:13, Mukesh <efex...@newsgroups.nospamwrote:
i have coded like this

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:Label ID="Label1" runat="server">
<asp:FileUpload ID="fupLogo" runat="server" Visible="False">

<asp:Button ID="Button2" runat="server" Text="Upload"
OnClick="Button2_Click" Visible="False" />

</asp:FileUpload><asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="show Uploader " />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button2">
</asp:PostBackTrigger>
</Triggers>
</asp:UpdatePanel>

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<br/>";
}
else
{
Label1.Text +="file format not supported<br/>";
}
}
else
{
Label1.Text += "file not exist<br/>";
}

}

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".
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:FileUpload>
<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");
}
Regards,
Mykola

Jul 17 '07 #2

P: n/a
On Jul 17, 10:13 am, Mukesh <efex...@newsgroups.nospamwrote:
<asp:FileUpload ID="fupLogo" runat="server" Visible="False">

<asp:Button ID="Button2" runat="server" Text="Upload"
OnClick="Button2_Click" Visible="False" />
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:FileUpload>
<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");
}
Regards,
Mykola

Jul 17 '07 #3

P: n/a
Hi Mukesh,

I was replying too quick and didn't noticed the Button2 is causing a normal
postback instead of an async postback, therefore my previous reply doesn't
apply for your question. Sorry about that.

Thanks Mykola for the correct fix, I've tested this and it's working
correctly. Please test this on your side and let us know the result.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 18 '07 #4

P: n/a
Walter Wang [MSFT] wrote:
Hi Mukesh,

I was replying too quick and didn't noticed the Button2 is causing a normal
postback instead of an async postback, therefore my previous reply doesn't
apply for your question. Sorry about that.

Thanks Mykola for the correct fix, I've tested this and it's working
correctly. Please test this on your side and let us know the result.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Dear
Walter and mykola
Thanks for the reply

Jul 19 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.