User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 425,766 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,395 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 880 | Replies: 4
Reply
Join Date: Dec 2004
Posts: 37
Reputation: mindfrost82 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mindfrost82 mindfrost82 is offline Offline
Light Poster

Pass QueryString as Integer to UserControl

  #1  
Jun 9th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 50
Reputation: FaridMasood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
FaridMasood's Avatar
FaridMasood FaridMasood is offline Offline
Junior Poster in Training

Re: Pass QueryString as Integer to UserControl

  #2  
Jun 10th, 2008
you must try the

dim invID as integer = httpcontext.current("inventoryID")
Thanks and Best of Lusk,

Farid ud din Masood
MS.c (CS)
University of Agriculture, Faisalabad
Reply With Quote  
Join Date: Dec 2004
Posts: 37
Reputation: mindfrost82 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mindfrost82 mindfrost82 is offline Offline
Light Poster

Re: Pass QueryString as Integer to UserControl

  #3  
Jun 10th, 2008
Originally Posted by FaridMasood View Post
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!
Reply With Quote  
Join Date: Feb 2008
Posts: 51
Reputation: a496761 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
a496761 a496761 is offline Offline
Junior Poster in Training

Re: Pass QueryString as Integer to UserControl

  #4  
Jun 10th, 2008
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'
Reply With Quote  
Join Date: Dec 2004
Posts: 37
Reputation: mindfrost82 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mindfrost82 mindfrost82 is offline Offline
Light Poster

Re: Pass QueryString as Integer to UserControl

  #5  
Jun 10th, 2008
Originally Posted by a496761 View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:36 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC