how do i do this, link postback

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jarremw
    New Member
    • Jan 2008
    • 50

    how do i do this, link postback

    ok, im trying to make a web app using asp.net and vb, what im doing is i have a mysqldatareader reading the database and writing links to the page, what i want to do is when the link is clicked, i want it to grab the data that is associated with the links row in the database and post it on a new page, here is my code, any help would be tremendous

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
    <a href = "courseinput.aspx">Input</a>
    <%  
        
        %>
    
        <form id="form1" runat="server">
        <div>
            Current Courses as of
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
            <br />
        </div>
        <%  Dim connection As New MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost;Database=sigma;User ID=root;Password=root") 'Provide the connection string to your database
        Dim cmd As MySql.Data.MySqlClient.MySqlCommand
        cmd = New MySql.Data.MySqlClient.MySqlCommand
        cmd.CommandText = "select course from course;"
        connection.Open()
        cmd.Connection = connection
            Dim reader As MySql.Data.MySqlClient.MySqlDataReader = cmd.ExecuteReader
    %>
            'this is where the links are posted to the page by the reader
            <% While reader.Read%>
            <ul>
                <li><a href = "#"><%Response.Write(reader(0))%></a></li>
                </ul>
            <%End While%>
            
        </form>
    </body>
    </html>
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    How do you want to post the data to your new page? If you had a class you could call it from both pages.
    Originally posted by jarremw
    ok, im trying to make a web app using asp.net and vb, what im doing is i have a mysqldatareader reading the database and writing links to the page, what i want to do is when the link is clicked, i want it to grab the data that is associated with the links row in the database and post it on a new page, here is my code, any help would be tremendous

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
    <a href = "courseinput.aspx">Input</a>
    <%  
        
        %>
    
        <form id="form1" runat="server">
        <div>
            Current Courses as of
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
            <br />
        </div>
        <%  Dim connection As New MySql.Data.MySqlClient.MySqlConnection("Data Source=localhost;Database=sigma;User ID=root;Password=root") 'Provide the connection string to your database
        Dim cmd As MySql.Data.MySqlClient.MySqlCommand
        cmd = New MySql.Data.MySqlClient.MySqlCommand
        cmd.CommandText = "select course from course;"
        connection.Open()
        cmd.Connection = connection
            Dim reader As MySql.Data.MySqlClient.MySqlDataReader = cmd.ExecuteReader
    %>
            'this is where the links are posted to the page by the reader
            <% While reader.Read%>
            <ul>
                <li><a href = "#"><%Response.Write(reader(0))%></a></li>
                </ul>
            <%End While%>
            
        </form>
    </body>
    </html>

    Comment

    • jarremw
      New Member
      • Jan 2008
      • 50

      #3
      i would like to post it using the datareader and let the reader read everything to the new page, something like when the user clicks on the link it will search the db for the row associated with that string of text and post it to another page called post where there would be labels to fill in for each part found in the db

      basically, i am wanting to know what link is clicked by the user so i can get the link text, search the db, and post to a new page with the information, sorry if im not being clear enough, ive been trying to do postback but cant really find anything that deals with links...

      so the events would be
      link is clicked
      link text is stored in a string
      connect to db
      search for row associated with string
      send to new page called post.aspx
      return the results from the db for the link

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Originally posted by jarremw
        ...when the link is clicked, i want it to grab the data that is associated with the links row in the database and post it on a new page, here is my code, any help would be tremendous
        Why not let the other page do the reading? Use a querystring/session object to pass the key information to the next page and let that page do the actual selecting. No need to pass large amounts of data from page to page.

        Comment

        • jarremw
          New Member
          • Jan 2008
          • 50

          #5
          ok, i just looked around on that, but how would handle this when the reader is creating the link for me?

          while reader.read
          <a href = "post.aspx" lname = "<% response.write( reader(0)) %>
          end while

          i have the reader creating the link for me from each row in the db so that means that essentailly every link would be same right?, so how would i handle this event? or will the page know what linked was click so that when i call for the querystring, it will have the clicked links text

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            Originally posted by jarremw
            ok, i just looked around on that, but how would handle this when the reader is creating the link for me?

            while reader.read
            <a href = "post.aspx" lname = "<% response.write( reader(0)) %>
            end while

            i have the reader creating the link for me from each row in the db so that means that essentailly every link would be same right?, so how would i handle this event? or will the page know what linked was click so that when i call for the querystring, it will have the clicked links text

            Can't you set the value of that reader to a variable, and then use the variable to build your link and link text? I'm not too familiar with the way you are doing things, this looks more like classic ASP.

            Comment

            • jarremw
              New Member
              • Jan 2008
              • 50

              #7
              yeah im just now learning asp.net, ive been doing vb for about 8 months, what methods would i use to do this in asp.net? basically what should i google because ive been looking around, i just dont know really what to look for, about the only thing that i have seen is postback stuff but that sounds like a lot to do for my webapp...

              thanks for the quick replies...

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Originally posted by jarremw
                yeah im just now learning asp.net, ive been doing vb for about 8 months, what methods would i use to do this in asp.net? basically what should i google because ive been looking around, i just dont know really what to look for, about the only thing that i have seen is postback stuff but that sounds like a lot to do for my webapp...

                thanks for the quick replies...
                Look up SqlDataSource, and Repeater, for starters. These are really useful for what you need. That would likely be how I would do it. Just set up your sql statement to select the key column (like an id or something) and then the other data you want. Then use the repeater to make a repeating list of links. Use the key data for the link itself, like:
                post.aspx?id=va lue
                And use the other info for the link text.

                Here's some sample code from one of my applications that uses the SqlDataSource and Repeater controls:
                [code=asp]
                <asp:SqlDataSou rce ID="sd1" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:AccessConnec tionString %>"
                SelectCommand=" SELECT [idDepartment], [dept] FROM [departments]"></asp:SqlDataSour ce>
                <asp:Repeater ID="Repeater1" runat="server" DataSourceID="s d1">
                <ItemTemplate >
                <a href="test.aspx ?id=<%# Eval("iddepartm ent") %>">
                <%# Eval("dept") %>
                </a>
                <br />
                </ItemTemplate>
                </asp:Repeater>
                [/code]

                What you would want to do is go into Design mode, and then drag a SqlDataSource onto the page. Then configure it, and then drag a repeater onto the page. Set the repeater's datasource to the id of the SqlDataSource you just used. Then use the <%# Eval("value") %> (replace value with the column name) to return the value for that row.

                Just google for them to get more familiar with it.

                Comment

                • jarremw
                  New Member
                  • Jan 2008
                  • 50

                  #9
                  so will this help me with the links? like if i display just the title of the course on the page and when they click on the title link, it gets the rows associated with that clicked link and displays the info on another page?

                  Comment

                  • Curtis Rutland
                    Recognized Expert Specialist
                    • Apr 2008
                    • 3264

                    #10
                    Originally posted by jarremw
                    so will this help me with the links? like if i display just the title of the course on the page and when they click on the title link, it gets the rows associated with that clicked link and displays the info on another page?
                    Are you trying to list courses on one page, and then display information about the selected course on another? If so, then yes, this can do that. Basically all this is doing is generating links for you. On your next page, you have to handle that. You can get to the value stored in the querystring using this:
                    if your link is:
                    post.aspx?id=12 3
                    use
                    Request.QuerySt ring("id")

                    That would return 123. Then use a select statement to get all the data you need for that record and populate the controls on the page.


                    If you learn a little more about these controls and how to use them, you will see how they apply to this situation.

                    Comment

                    • jarremw
                      New Member
                      • Jan 2008
                      • 50

                      #11
                      ok thank you so much, i finally understand this (kinda) haha thanks for the help and the quick replies, i love this site

                      Comment

                      • jarremw
                        New Member
                        • Jan 2008
                        • 50

                        #12
                        so i have a strange problem now, ive got the repeater to connect to my mysql db and fill in my links, now my problem is when i pass the querystring.... ..when set a labels text property to the querystring, it comes out right, but when i try to include in a sql statement something like
                        select * from course where course = '" & this is the variable that holds my requested querystring & "' and run it through a data reader and nothing comes out at all, ive tried in both a page_load event and in the source of the page....any ideas?

                        Comment

                        Working...