hi
i use these code to uploading image
<asp:UpdatePanel ID="Upbdt" runat="server">
<ContentTemplate>
<asp:ModalPopupExtender DropShadow="true" ID="ModalPopupExtender"
PopupControlID="PnPopup" runat="server" TargetControlID="BtnPopup"
>
</asp:ModalPopupExtender>
<asp:Button ID="BtnPopup" OnClick="BtnPopup_Click" runat="server" Text="upload" CssClass="DPC9_Img1" BorderStyle="Solid" BorderWidth="0px" BorderColor="White" />
<asp:Panel ID="PnPopup" runat="server" BackColor="White"
CssClass="panel">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/image/close.png" />
<br />
<asp:FileUpload ID="AsyncFileUpload1" runat="server"
ToolTip="click" />
<br />
<asp:Button ID="BtnUpload" OnClick="BtnUpload_Click" runat="server" Text="load" />
<asp:Label ID="lblMessage" runat="server" Text=" "></asp:Label>
<asp:Label ID="Label20" runat="server" Text="Label"></asp:Label>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="BtnUpload" />
</Triggers>
</asp:UpdatePanel>
behind code
protected void BtnUpload_Click(object sender, EventArgs e)
{
string path = Server.MapPath(".") + "\\../Upload\\";
string[] validext = { ".jpg", ".gif", ".png", ".rar" };
string ext =
System.IO.Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
lblMessage.Text = "please enter .jpg .png .gif format.";
return;
}
//4-Get File Name
string filename = System.IO.Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);
//5-Get File Exist and if (true)Generate New Name
while (System.IO.File.Exists(path + "\\" + filename))
filename = "1" + filename;
//6-Save File to Server
if (AsyncFileUpload1.HasFile)
{
try
{
// Set file size limit(in bytes) condition to disable the
// users to upload large files. Here 1024 bytes = 1 kilobyte.
if (AsyncFileUpload1.PostedFile.ContentLength < 1050)
{
// SaveAs method of PostedFile property used
// to save the file at specified rooted path
AsyncFileUpload1.PostedFile.SaveAs(Server.MapPath("~/Upload") + System.IO.Path.DirectorySeparatorChar + AsyncFileUpload1.PostedFile.FileName);
// success message
Label20.Text = "File " + AsyncFileUpload1.PostedFile.FileName + " uploaded successfully.";
}
else
{
// file size limit exceeded
Label20.Text = "File size of " + Convert.ToString(AsyncFileUpload1.PostedFile.ContentLength / 1024 ) + " KB is exceeding the uploading limit.";
}
}
catch (Exception ex)
{
// error message
Label20.Text = "Some problem occurred while uploading the file. Please try after some time.";
}
}
else
{
// warning message
Label20.Text = "Please choose a file to upload.";
}
AsyncFileUpload1.PostedFile.SaveAs(path + filename);
SqlCommand _cmd = new SqlCommand("Fileup1", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();
_cmd.Parameters.AddWithValue("@image", AsyncFileUpload1.FileBytes);
_cmd.Parameters.AddWithValue("@behcode", "8888");
_cmd.Parameters.AddWithValue("@name", "test");
_cmd.ExecuteNonQuery();
_cn.Close();
here in UpdatePanel i have 2 lable :1-lable20 and 2-lblMessage
these lable show error message when Extension and size of image are out of limit.
problem is when i.e I upload .rar file and click on BtnUpload button it exit from popup window and i cant't see error message i should click on upload button again untill again show popup window after that i can see error message
i want it doesn't exit from popup window until user enter correct format of image if they don't enter correct format they can see error on popup window
Best regards