Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2010, 06:39 PM
Authorized User
 
Join Date: Jul 2010
Posts: 23
Thanks: 7
Thanked 2 Times in 1 Post
Default Random redirect, why?

Hi

I have a strange problem. I have a thumbnail for a random picture, with the following code in my page_load event to generate it.

Code:
            ...
            Dim PicCount = From pic In myEnt.Pictures
                           Select pic

            Dim rand As New Random()
            Dim randomImg As Int16 = rand.Next(0, PicCount.Count - 1)

            Dim randImg = From pic In myEnt.Pictures
                          Order By pic.Id Ascending
                          Skip randomImg
                          Select pic

            FormView4.DataSource = randImg
            FormView4.DataBind()
            ...
In the click event sub i have this code:
Code:
        Using myEnt As New PicturesEntities()

            Dim imgb As ImageButton = FormView4.FindControl("Rand")

            Dim rImg = From pic In myEnt.Pictures
                           Order By pic.Id
                           Where pic.ThumbnailUrl = imgb.ImageUrl
                           Select pic.Id

            Response.Redirect(String.Format("~/?={0}", rImg.First))
        End Using
Now, my problem is that when i click the thumbnail, i just go to a random site and not the one wich is previewed by the thumbnail. I have tried several different solutions wich all should work, atleast in my little mind but with the same result every time.

I guess i am not finding the "right" ImageButton, but im too green to figure out why.
 
Old August 29th, 2010, 08:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Difficult to say as you're not posting the complete code, but I guessing that you bind the FormView in Page_Load when the page initially loads, and after a PostBack. When the postback happens. you assign a new random image and link.

Wrap your code in If Not Page.IsPostBack Then and it probably works. If not, please post more code.

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!
The Following User Says Thank You to Imar For This Useful Post:
andreas5 (August 29th, 2010)
 
Old August 29th, 2010, 11:28 AM
Authorized User
 
Join Date: Jul 2010
Posts: 23
Thanks: 7
Thanked 2 Times in 1 Post
Default

It worked! You are like a god to me!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Random value(in C#) Banishah ASP.NET 3.5 Basics 5 June 24th, 2009 01:26 PM
Random value(in C#) Banishah ASP.NET 2.0 Basics 5 June 24th, 2009 01:04 PM
random number rajuru Beginning PHP 7 December 7th, 2004 10:52 AM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.