I'm using ASP.NET and VB 2005. I'm trying to get a QueryString passed in the URL into a UserControl and I need to pass it as an integer because that is how it will be pulled from the database.

Here is part of the .aspx page:

<%@ register src="frmOrderProductDisplay.ascx" tagname="ProductDisplay" tagprefix="uc1" %>
    <div>
        <br />
        <h3>
            Item Details</h3>
        <uc1:ProductDisplay ID="ProductDisplay1" runat="server" inventoryID='invID' />
        <br />
        <asp:Button ID="btnContinue" runat="server" PostBackUrl="~/frmOrder.aspx" Text="Continue Shopping" /><br />
        <br />
    </div>

Here is my VB Code Behind file:

Partial Class frmOrderItemDetail
    Inherits System.Web.UI.Page

    Dim sInvID As String
    Dim invID As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sInvID As String = Request.QueryString("invID")
        Dim invID As Integer = Int32.Parse(sInvID)
    End Sub
End Class

Basically I'm pulling invID from the URL and I need inventoryID in uc1 to be the value of invID as an integer.

If I put inventoryID="3" in the uc1, then it works fine. No matter how I try to set inventoryID equal to the int value of invID I get a "Input string was not in a correct format" error.

I'm sure its something simple I'm just missing, so any help would be appreciated.

you must try the

dim invID as integer = httpcontext.current("inventoryID")

Where would I put that and what would it replace?

Also, in my aspx file, would I leave it as: inventoryID='invID' or do I need to change how it calls invID?

Thanks!

If you have a public property in your control name inventoryID, then in the page's code-behind, in the Page_Load event, add the line

ProductDisplay1.inventoryID = Request.QueryString("invID")

If the property is strongly typed, it will only accept an integer. You can remove the following attribute from the instance of your control in the .aspx file.

inventoryID='invID'

If you have a public property in your control name inventoryID, then in the page's code-behind, in the Page_Load event, add the line

ProductDisplay1.inventoryID = Request.QueryString("invID")

If the property is strongly typed, it will only accept an integer. You can remove the following attribute from the instance of your control in the .aspx file.

inventoryID='invID'

Thanks! That worked perfectly, I didn't even think about doing it that way for some reason.

This article has been dead for over six months. Start a new discussion instead.