Problem Solved : After Downloading file, Update progress remains

What the Problem was ? I made an update panel, inside it was a file link(link button). On click of the file link update progress starts showing the loading image, when the download box comes either you save, open or close it. Loading/Spinning image is still there.

Actual code creating the problem was ? Response.redirect was redirecting the page to FileDownload.aspx ,from where the download box(file) comes with the save, open or close options.

Solution : Remove the Response.redirect(“FileDownload.aspx”) and redirect to this page with javascript.

STEP 1: Replace the Response.Redirect(“FileDownload.aspx”) with this :

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Download", "GotoDownloadPage();", true);

this will call the javascript function GotoDownloadPage();

STEP 2 : Define the function within javascript script tag as

GotoDownloadPage()
{
window.location=”FileDownload.aspx”
}

Problem Solved.

Tip: if you want to send some documentId like parameters to the FileDownload page, you can use session variables.

Thnx. Happy Coding…

Advertisements

Problem Solved : FileUpload control inside GridView

How the problem arises? I made a gridview inside it was a fileupload control, in a column on every row with Update(Link Button). When the upload button is clicked, the file gets uploaded along the row. Now to show the Uploaded file , the aspx page needs to be reload and this caused the problem.

What the problem was? If you are in some inner page of the gridview like say fifth and you uploaded the file in certain row there after uploading the file you are being redirected to the first page of the gridview.

Some Initials You may know to solve the problem : I was having general paging in the gridview.
GridView1_PageIndexChanging()
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}

I was handling the Upload click with command=”Upload”
and after handling it, i made a Response.Redirect("samepage.aspx");

Solution : I maintained the paging for this problem by taking two session variables, one for storing the page index in session variable every time and another one to ensure the Upload button is clicked.

I did this in 3 easy steps:
Step 1 :
Add the following line :
GridView1_PageIndexChanging()
{
GridView1.PageIndex = e.NewPageIndex;
//Making session variable to know the page index
Session["PageIndex"] = e.NewPageIndex;
GridView1.DataBind();
}

Now i know the page index, everytime the page index got clicked.

Step 2 :
Making the page to know the update button is clicked
Add the following line above redirecting the page to self :
Session["PageUploaded"]="true";
Response.Redirect("samepage.aspx");

Step 3 :
Now I have to just handle the response.redirect of Upload Button Click.

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//place this code above binding data to GridView
if(Session["PageUploaded"] != null)
{
GridView1.PageIndex = int.Parse(Session["PageIndex"].ToString());
Session["PageUploaded"] = null;
}
GridView1.DataBind();
}
}

Thnx. Happy Coding…