|
 |
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

June 29th, 2009, 08:22 PM
|
Registered User
|
|
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Refresh/Redirect to a particular Formview Page Index?
I have a page with a Gridview and FormView and a button which uploads an image file to a folder, (the FormView contains the file as an image).
The ButtonClick satisfactorily uploads the file, but a viewer has to refresh the page to see the new picture, which is not what I expect them to have to do.
here is the code that renames the file and saves it, after some previous code has uploaded it from a viewers drive... it also tries using response.redirect, but this merely opens a new page at the first record of the FormView:
Code:
Public Sub SaveFile2(ByVal FileUp As FileUpload)
Dim fileName1 As String = String.Format("{0}.jpg", FormView1.DataKey.Value)
Dim filePath1 As String = Server.MapPath("~/Dogimages/" & fileName1)
FileUp.SaveAs(filePath1)
Response.Redirect("Dogsdata.aspx#formview")
End Sub
What could I use to refresh the page to renew the image, and open the new page at the record with the new image?
The Formview1.Datakey.Value is the PrimaryKey ID of the record, so if I could capture that and use it to somehow make the page open at the record with that ID, that would be a solution... I just dont know how to do it.
I'm flying by the seat of my pants here, so detailed explanation would be appreciated.
Many Thanks
Richard
Last edited by richard10002; July 4th, 2009 at 08:38 PM.
|

July 4th, 2009, 05:09 AM
|
 |
Wrox Author
Points: 71,804, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,050
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
|
|
Hi there,
Can you show more code here? It's not entirely clear when your data gets updated or how your page is set up.
Typically, however, when you want to refresh your data, you call DataBind on the relevant control. So, if you want to refresh a GridView you call:
myGridView.DataBind()
from your Button's Click handler (or from another location where it makes sense)
This forces the control to get and display updated data.
Hope this helps,
Imar
|

July 4th, 2009, 08:36 PM
|
Registered User
|
|
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Refresh/Redirect to a particular Formview Page Index?
Hi Imar,
Many Thanks!! That's done the trick.... I've got rid of the Response.Redirect, and the code now reads:
Code:
ProtectedSub SaveFile2(ByVal FileUp As FileUpload)
Dim fileName1 AsString = String.Format("{0}.jpg", FormView1.DataKey.Value)
Dim filePath1 AsString = Server.MapPath("~/Dogimages/" & fileName1)
FileUp.SaveAs(filePath1)
FormView1.DataBind()
EndSub
and it works fine - loads the image, and refreshes it with no further action on the users part.
I wonder if you could help with "refreshing" the page so that it opens at the Formview, which is halfway down the page, rather than at the Gridview, which is at the top of the page? This would save the user having to scroll down the page to see the image they have just uploaded.
Do you still want to see more code? (I may have confused the issue by referring to a DetailsView in my original post :( . I've edited it now to refer to FormView... which is what I meant - apologies
Many Thanks
Richard
Last edited by richard10002; July 4th, 2009 at 08:40 PM.
|

July 5th, 2009, 04:58 AM
|
 |
Wrox Author
Points: 71,804, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,050
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
|
|
Hi Richard,
You can try setting the MaintainScrollPositionOnPostback: http://msdn.microsoft.com/en-us/libr...npostback.aspx This automatically scrolls back the page to where it was when you posted it back.
If that's not good enough (e.g. you need to scroll to a different position) take a look here:
http://www.4guysfromrolla.com/articles/111704-1.aspx
It explains how to implement MaintainScrollPositionOnPostback before it was added to the Page class and gives you some ideas on implementing something like this.
Cheers,
Imar
|

April 22nd, 2015, 12:37 PM
|
Friend of Wrox
|
|
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
|
|
Hi Imar,
http://www.4guysfromrolla.com/articles/111704-1.aspx - this link works great across postbacks - thank you.
Is there any way to maintain scroll position when redirecting to the same page?
thanks.
Tulsi
|

May 3rd, 2015, 11:47 AM
|
 |
Wrox Author
Points: 71,804, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,050
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
|
|
You can probably do something similar but maintain the position through a field on the query string.
Cheers,
Imar
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |