p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 29th, 2009, 08:22 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 4th, 2009, 05:09 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 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
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 4th, 2009, 08:36 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 5th, 2009, 04:58 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 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
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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
How to refresh datagrid without refresh whole page avanishp ASP.NET 1.1 1 September 13th, 2005 01:43 PM
Redirect to another page kumarop ASP Forms 3 March 10th, 2005 06:46 AM



All times are GMT -4. The time now is 04:31 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc