Reputation: 1841
Im trying to pass a value bounded with a button in form1.aspx to form2.aspx
form1.aspx:
<asp:Button ID="Button1" runat="server" Text="Button" CommandArgument = '<%#Eval("Parking_ID")%>' />
the button is within a repeater which is bounded to a datasource that Select * From [Parking]
Each button in the repeater should have a unique parking_Id
based on CommandArgument
.
In form1.aspx.vb:
Protected Sub repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repeater1.ItemCommand
Dim value As Int32 = Convert.ToInt32(e.CommandArgument)
Response.Redirect("form2.aspx?id=" & value)
Session("field4") = value
In Form2.aspx.vb:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim field4 As String = CType(Session.Item("field4"), String)
Parking_ID1.Text = field4
But the Parking_ID1.text Label
is not showing any values.
Any help would be appreciated
Regards
Upvotes: 0
Views: 834
Reputation: 1408
You're redirecting before you set the session.
Also, you can more easily pickup the value in Form2.aspx.vb by just doing:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim field4 As String = Request.Querystring("id")
Parking_ID1.Text = field4
You'll have to forgive my VB.net syntax, long time since I used it, but the concept should work for you.
Extending the answer based upon a request from the poster:
Should you wish to pass multiple parameters across, there are a few ways of doing it, though your model is the right basis for this:
Protected Sub repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repeater1.ItemCommand
Dim value As Int32 = Convert.ToInt32(e.CommandArgument)
Dim dataItem as YourStronglyTypedItem = e.Item.DataItem as YourStronglyTypedItem // c# there - sorry
Session("field4") = dataItem.Property1
Session("field5") = dataItem.Property2 // etc.
Response.Redirect("form2.aspx?Parking_ID=" & value & "&OtherProperty=" & dataItem.Property2)
The syntax isn't ideal (and some of it is in c#, sorry!), but essentially, if you can grab the bound data item (through e.Item.DataItem) and cast it to whatever object you bound in the first place then you can grab as many properties from it as you like.
So say you databound List to it. e.Item.DataItem cast to Widget will give you the values of that particular widget, then you can either set multiple session values (or indeed just put the whole widget into session), or you can pass multiple query string parameters as I have done above.
hope that helps?
Upvotes: 2
Reputation: 10115
You can follow the correct syntax below. Dim field4 As String = Request.QueryString["id"]
Upvotes: 0