Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In Asp.Net,I am using a response.write technique to download a file on aGridView_RowCommand event. The Response.End() or something else is causing the UpdatePanel.Update() call to not perform>

Here is a summary and code parts of what I am doing.

I have a label Label1 and a textbox TextBox1 on my page as well as GridView1.
Both Lablel1 and TextBox1 are in an Update Panel.
I have a button with a command event that will update the text for Label1 and Textbox1 when the button is clicked.
VB
Sub Button1_Command(sender As Object, e As CommandEventArgs) Handles Button1.Command
   TextBox1.Text = e.commandargument
   Label1.Text = e.commandname
   Updatepanel1.Update()
sub end

This all works so I have my Updatepanel and other code working as expected.

Now, I next want to download a file after the user selects which file in a GridView
Here is how that is setup and is working:
VB
Protected Sub GridView1_RowCommand(.details...) Handles GridView1.RowCommand
    ' set up parameters etc here  code not shown
     dim status as string
     Response.ContentType = "xxx/xxx"
     Response.AddHeader("Content-Disposition", "attachment; Filename= filename")
     Response.AddHeader("Content-Length", fileLength)  
    ' set up bytes array with a file stream other code not shown
     Response.BinaryWrite(bytes)
    
    '  Actually there is more code that sets the string 'status' if there are errors 
    '  so lets assume that the above worked and string status = "Success"
    ' I want to set Lablel1.text and Textbox1.text at this point something like:
    '  I tried this but the text is not updated at the client
    Label1.Text = "Status"
    TextBox1.Text = status
    UpdatePanel1.Update()   

    ' I also tried this but it also does not show the new text at client
     Button1_Command(sender, New CommandEventArgs("Download Status", status))
    ' obviously the call is not a new client event
    ' the last statement in the sub is Response.End()  If I leave it out makes no 
    ' difference to my issue  
     Response.End()
end sub

I have not shown all the code but it mostly works - the file is downloaded and the client page is now waiting for user input to create a new request event. What I want to do is update the TextBox and Label after the Respone.End().

I suspect the Response.End() ends the client request / event so UpDatePanel1.Update does not work. And, as you probably know, TextBox1 and Label1 are not updated with my call to Button1_Command() because the response has ended and there is no button1 "event" . I suppose I could programatically set the CommandEventArgs for the button and wait for the user to click the button to get the status but why ask the user to do that - not nice.

I tried putting the file download code in Gridview_SelectedIndexChanging which is of course followed by SelectedIndexChanged where I set TextBox1.text and did UpdDatePanel.Update(). That also did not display at client. I suspect the event that calls either RowCommand or SelectedIndexChanging is ended with the Reponse.End()

Is there a way to do what I am trying do (update browser page in the UpdatePanel without the user clicking a button or in anyway interacting with the page after the download has completed.

Perhaps some client script / server code to accomplish what I want.

Or, perhaps some type of trigger event that occurs every second, that I could enable just before updating the textbox/label then disable right after the first tick.

I have searched for an answer to this for several days now and have not found a similar situation (I.E. client has no event or response pending and the response is complete)

Links to examples or suggestions to narrow my searches would be helpful and much appreciated.

Dennis
Posted
Updated 11-Dec-14 13:05pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900