Click here to Skip to main content
15,914,225 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm trying to create a link to send a value to the next page, and then use this value on this page.

Inside a Datalist.
ASP.NET
<asp:linkButton ID="Datalnk1" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "ID")%>' CommandName="lnk" PostBackURL='~/Page/Event/popup.aspx' runat="server"><%#DataBinder.Eval(Container.DataItem, "ID")%
></asp:Linkbutton>


link retrieves the correct SQL info (ID) and open the next page Popup.aspx

Page Popup.aspx
ASP.NET
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <div id="meldpå"  runat="server">
         Event:
        <asp:Label ID="confirmlabel" runat="server"></asp:Label>
        <br />
        <br />
        <asp:TextBox ID="name1" runat="server">Navn:</asp:TextBox>
        <br />
        <br />
<asp:Button ID="inexsql1" runat="server" Text="Send !!" OnClick="inexsql1_Click" />


codefile Popup.aspx.vb
VB
Partial Class Page_Event_popupPage
    Inherits System.Web.UI.Page

    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim name As String

    Public Sub Page_Load()
        Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("MainContent"), ContentPlaceHolder)

        Dim ID As String = String.Empty
        If Not String.IsNullOrEmpty(Request.QueryString("ID")) Then
            ID = Request.QueryString("ID")
        End If

        confirmlabel.Text = "ID"

    End Sub

    Protected Sub inexsql1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim MainContent As ContentPlaceHolder = CType(Page.Master.FindControl("MainContent"), ContentPlaceHolder)

        Dim name As TextBox = TryCast(Page.FindControl("name1"), TextBox)

        con = New SqlConnection("Data Source=VINYW8;Initial Catalog=Events;Integrated Security=True")
        cmd = New SqlCommand("INSERT INTO Påmeldt (Event, Navn)VALUES(@R1, @R2)", con)
        cmd.Parameters.AddWithValue("@R1", ID)
        cmd.Parameters.AddWithValue("@R2", name.Text)
        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub
End Class


trouble is that I do not get the value in the link with me to the next page, and i think the code in the first page has an error.
but I'm not sure if get and store, to use later on is correct to. (on popup page)
and I use Master.Page with content placeholders.
Posted
Updated 28-Sep-13 2:25am
v2

1 solution

You want to send the ID as querystring but there is no querystring added in:
HTML
PostBackURL='~/Page/Event/popup.aspx'
that is why you are not getting anything on next page.
You need to use
XML
<%#DataBinder.Eval(Container.DataItem, "ID")%>
to add a querystring in the PostBackURL

Good luck
 
Share this answer
 
v2
Comments
prototypen 28-Sep-13 16:09pm    
thanks

I changed the PostBackURL to:
<%# String.Format("popup.aspx?id={0}", DataBinder.Eval(Container.DataItem, "id"))%>
and first page works, now I just need to correct my second page.
Azee 28-Sep-13 16:54pm    
Ok, from your code in the second page, I get that you are trying to insert a record in the database using that QueryString and the TextBox value in the Button event. First thing I don't understand is why you are using Page.FindControl to get the TextBox, if its on your page you should be able to use it with just its ID.

Anyway you should move the code to get querystring from Page_Load to your Button's click event because that's where it'll be used.
That's it, I don't see anything else wrong with code. If you find one, try debugging.
prototypen 28-Sep-13 17:57pm    
Thanks again.

I was working on the page, and i discovered that i was finding the textbox 2 times.
When I removed this the TextBox value was send inn.

and i was trying to get the ID to work, (it send to the sql table "_page")

when i moved the code you suggested, everything seemed to work.

if i do not use the Page.Master.FindControl in top the button and textbox don`t work. Error: is not declared)

Thank you again for helping me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900