954,168 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pass QueryString as Integer to UserControl

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>
        
        <h3>
            Item Details</h3>
        <uc1:ProductDisplay ID="ProductDisplay1" runat="server" inventoryID='invID' />
        
        <asp:Button ID="btnContinue" runat="server" PostBackUrl="~/frmOrder.aspx" Text="Continue Shopping" />
        
    </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.

mindfrost82
Light Poster
38 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

you must try the

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

FaridMasood
Junior Poster in Training
59 posts since Mar 2007
Reputation Points: 8
Solved Threads: 0
 

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!

mindfrost82
Light Poster
38 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

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'
a496761
Junior Poster in Training
62 posts since Feb 2008
Reputation Points: 10
Solved Threads: 4
 

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.

mindfrost82
Light Poster
38 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You