page refreshing

Bryan

Freshman
Joined
Jun 17, 2002
Messages
49
Location
Cedar Hill, TX
Hello all, I am new to ASP.net and I am trying to write a photo gallery. I'm just getting started with the ASP.net and whenever I try to walk through the pictures on mysql server the page refreshes and resets the counters to 0 and I every time I click next I get the same picutre. It starts off with the bush logo, because that is part of the aspcode as seen below. Then when you click next the happy face logo shows up. As it should. This tells me my sql connection is working. But when you click next again you get the happy face logo and not the found saddam pic that you should. Don't worry about the previous button, it doesn't work yet, I haven't written code for it.
you can view the page at http://209.30.46.201/Chapter_07/CompoundProgrammatic.aspx
the three images that you should see are after the next & previous buttons.
here is the vb.net code that I am using.
PHP:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Label6.Text = n.ToString
        n = n + 1
        Image1.ImageUrl = GetImage(n)
        n = n + 1
        Label6.Text = n.ToString
    End Sub
    Private Function GetImage(ByVal x As Integer) As String
        Dim strConnection As String = "server=localhost\SQL;database=images;integrated_security=true"
        strConnection = "data source=BRYANPC\SQL;initial catalog=images;integrated security=SSPI;persist security info=False;workstation id=BRYANPC;packet size=4096"
        Dim cn As SqlConnection = New SqlConnection(strConnection)
        cn.Open()
        Dim strSelect As String = "SELECT * FROM ImageList"
        Dim dscmd As New SqlDataAdapter(strSelect, cn)

        Dim ds As New DataSet()
        dscmd.Fill(ds, "Images")

        cn.Close()

        Dim dt As DataTable = ds.Tables.Item("Images")
        Dim rowImage As DataRow
        rowImage = dt.Rows(x)
        GetImage = rowImage("ImageURL")
    End Function
here is the html/asp.net code I have for the control
PHP:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="Compound.ascx.vb" Inherits="Chapter_07.Compound" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

<P><asp:label id="Label1" Font-Size="Large" Font-Bold="True" runat="server">Compound Interest Calculator</asp:label></P>
<P><asp:label id="Label2" runat="server">Principal ($):</asp:label><asp:textbox id="TextBox1" runat="server"></asp:textbox></P>
<P><asp:label id="Label3" runat="server">Rate (%):</asp:label><asp:textbox id="TextBox2" runat="server"></asp:textbox></P>
<P><asp:label id="Label4" runat="server">Years:</asp:label><asp:textbox id="TextBox3" runat="server"></asp:textbox></P>
<P><asp:label id="Label5" runat="server">Compounding Frequency:</asp:label><asp:dropdownlist id="DropDownList1" runat="server">
		<asp:ListItem Value="1">Annually</asp:ListItem>
		<asp:ListItem Value="4">Quarterly</asp:ListItem>
		<asp:ListItem Value="12">Monthly</asp:ListItem>
		<asp:ListItem Value="365">Daily</asp:ListItem>
	</asp:dropdownlist></P>
<P><asp:button id="Button1" runat="server" Text="Calculate"></asp:button></P>
<P><asp:label id="Label6" runat="server"></asp:label></P>
<P><asp:image id="Image1" runat="server" ImageUrl="http://bryandaniel.com/bush.jpg"></asp:image></P>
<P><asp:button id="Button2" runat="server" Text="<-- Prev"></asp:button> 
	<asp:button id="Button3" runat="server" Text="Next -->"></asp:button></P>
 
I don't know how 'n' is defined it appears you have a display on the field and it keeps displaying 2. How many images do you have..
 
Hey,

The problem is that the value of the variable n is lost after each page view.

When I open the page the bush picture is shown because it is defined in the html.
When I click the next button, the code converts the value of n to a string. But the value of n will always be 0 because it is forgotten after a page view. Then twice, the code adds 1 to the value of n. The result of that is 0 + 1 + 1 = 2, so the code always shows picture number 2. You follow me? ;)

What you can do to solve the problem is to save the number in the label instead of the variable n.

Hope that helps.

Dennis
 
Back
Top