Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 29th, 2009, 08:22 PM
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old July 4th, 2009, 05:09 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old July 4th, 2009, 08:36 PM
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #4 (permalink)  
Old July 5th, 2009, 04:58 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old April 22nd, 2015, 12:37 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old May 3rd, 2015, 11:47 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

You can probably do something similar but maintain the position through a field on the query string.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Confirm Page for insert formview mar0364 BOOK: Beginning ASP.NET 2.0 and Databases 0 February 22nd, 2007 10:34 PM
redirect to page other than default page sarah lee ASP.NET 1.0 and 1.1 Basics 3 December 15th, 2006 05:45 PM
Redirect to new page without closing current page peter2004 ASP.NET 2.0 Basics 5 June 5th, 2006 09:49 PM



All times are GMT -4. The time now is 07:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.