File Upload Control With Update Panel IN Asp.net

Hello Friend Toady YOu Will learn About File upload control of Without Ajax and Async File Uplaod Control of Ajax which have introduced New Release of Ajax
first You Will Learn about How to Use the traditional way of File upload when it was not int AJax Toolkit
Step1 : Make a new website In Visual Studio 2008 and Add a new master page into your application As below given design


Step 2: Now Add a Content page by right click on your master page and place update panel into Your Content page with Script Manager

 
Link doc.
 

Step 3: Master Page Source Code Will Be As Below Given

STep 4: And Into code file of master page write down this method

public void RegisterPostbackTrigger(Control triggerOn)
{
ScriptManager1.RegisterPostBackControl(triggerOn);
}

Step 5: Now Double Click ON Submit Button ANd Write down the below given code in code behind file of content page
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
((ASP.masterpage_master)Page.Master).RegisterPostbackTrigger(btnSubmit);

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
String _strTenderDocument = string.Empty; ;
if (FileUpload1.HasFile)
{
try
{

Random r = new Random();
_strTenderDocument= r.Next(10, 10000) + r.Next(10, 10000) + “.” + (Convert.ToString(FileUpload1.FileName).Substring(Convert.ToString(FileUpload1.FileName).Length – 4, 4)).ToString();

//UploadedDocuments Create this directory into ur web application

FileUpload1.SaveAs(Server.MapPath(“~/UploadedDocuments/” + _strTenderDocument));
Response.Write(_strTenderDocument);
}
catch (Exception ex)
{

Response.Write(“Warning!!! There is an error with uploading tender document.
Error in:-” + ex.Message);
}
}
else
{

Response.Write(“Caution!!! You are floated an tender without any tender document.”);
}
}
}
STep 6: Now Make A Directory with UploadedDocuments Name where your uploaded document will be saved and run your application you will see on post back your file upload control will work into update panel.
and saved the document within desire location.
Hope You Will Be Happy with this use.
and enjoy in Programing world.
Fileupload Control Actually Want fullpost back so we need to fire the post back trigger.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s