|
 |
aspx thread: Help with user control property
Message #1 by info@e... on Wed, 17 Apr 2002 08:58:05
|
|
Hello all,
I am having trouble pasing a querystring value as a property to one of my
controls. My control is set to take a value on the property ProductID. I
want the page that is calling the control to provide the ProductID value,
that will be a dynamic field, either from a database or from the URL
Querystring. For example, I would need to read the following:
http://mysite.com?id=123456
123456 is what I would like to be in the ProductID value.
I tried the different codes below and none seem to pass the value:
------------------------------------------------------------------------
<uc1:control id="mycontrol" ProductID='<%Request.QueryString("id");%>'
runat="server">
</uc1:control>
<uc1:control id="mycontrol" ProductID='<%Request.QueryString["id"];%>'
runat="server">
</uc1:control>
<uc1:control id="mycontrol" ProductID='<%# Request.QueryString["id"]%>'
runat="server">
</uc1:control>
and I also tried puting it in a variable and then adding it:
<%string strID = Request.QueryString["id"]%>
<uc1:control id="mycontrol" ProductID='<%Response.Write(strID);%>'
runat="server">
</uc1:control>
I would also appreciate it if someone can show me how to easily put a data
field value into a variable. In classic asp it was fairly easy. I tried a
few different ways in ASP.net and I cannot get it right.
I would like the euivalent to the following classic code:
Dim strField
strField = rs.Fields.Item("field").Value
Thanks!
- Elmer M.
Message #2 by "Manuj Sarpal" <manujsarpal@h...> on Wed, 17 Apr 2002 10:03:12 +0100
|
|
Elmer try this in page load even of the user control.
PRODUCTID = Request.QueryString("ID").ToString
Hope it helps..
Manuj
----- Original Message -----
From: <info@e...>
To: "ASP+" <aspx@p...>
Sent: Wednesday, April 17, 2002 8:58 AM
Subject: [aspx] Help with user control property
> Hello all,
>
> I am having trouble pasing a querystring value as a property to one of my
> controls. My control is set to take a value on the property ProductID. I
> want the page that is calling the control to provide the ProductID value,
> that will be a dynamic field, either from a database or from the URL
> Querystring. For example, I would need to read the following:
> http://mysite.com?id=123456
>
> 123456 is what I would like to be in the ProductID value.
>
> I tried the different codes below and none seem to pass the value:
> ------------------------------------------------------------------------
> <uc1:control id="mycontrol" ProductID='<%Request.QueryString("id");%>'
> runat="server">
> </uc1:control>
>
> <uc1:control id="mycontrol" ProductID='<%Request.QueryString["id"];%>'
> runat="server">
> </uc1:control>
>
> <uc1:control id="mycontrol" ProductID='<%# Request.QueryString["id"]%>'
> runat="server">
> </uc1:control>
>
> and I also tried puting it in a variable and then adding it:
> <%string strID = Request.QueryString["id"]%>
> <uc1:control id="mycontrol" ProductID='<%Response.Write(strID);%>'
> runat="server">
> </uc1:control>
>
>
> I would also appreciate it if someone can show me how to easily put a data
> field value into a variable. In classic asp it was fairly easy. I tried a
> few different ways in ASP.net and I cannot get it right.
>
> I would like the euivalent to the following classic code:
> Dim strField
> strField = rs.Fields.Item("field").Value
>
>
> Thanks!
>
> - Elmer M.
>
>
Message #3 by "Minh T. Nguyen" <nguyentriminh@y...> on Wed, 17 Apr 2002 08:31:11 -0700
|
|
Elmer,
If you are using C#, the correct syntax is:
Request.QueryString.Get("id");
If you are using Request.QueryString[ -- then it expects an
index here indicating the nth element in the querystring. I'd assume
that VB.NET has a similar syntax.
Good luck,
Minh.
-----Original Message-----
From: info@e... [mailto:info@e...]
Sent: Wednesday, April 17, 2002 8:58 AM
To: ASP+
Subject: [aspx] Help with user control property
Hello all,
I am having trouble pasing a querystring value as a property to one of
my
controls. My control is set to take a value on the property ProductID. I
want the page that is calling the control to provide the ProductID
value,
that will be a dynamic field, either from a database or from the URL
Querystring. For example, I would need to read the following:
http://mysite.com?id=123456
123456 is what I would like to be in the ProductID value.
I tried the different codes below and none seem to pass the value:
------------------------------------------------------------------------
<uc1:control id="mycontrol" ProductID='<%Request.QueryString("id");%>'
runat="server">
</uc1:control>
<uc1:control id="mycontrol" ProductID='<%Request.QueryString["id"];%>'
runat="server">
</uc1:control>
<uc1:control id="mycontrol" ProductID='<%# Request.QueryString["id"]%>'
runat="server">
</uc1:control>
and I also tried puting it in a variable and then adding it:
<%string strID = Request.QueryString["id"]%>
<uc1:control id="mycontrol" ProductID='<%Response.Write(strID);%>'
runat="server">
</uc1:control>
I would also appreciate it if someone can show me how to easily put a
data
field value into a variable. In classic asp it was fairly easy. I tried
a
few different ways in ASP.net and I cannot get it right.
I would like the euivalent to the following classic code:
Dim strField
strField = rs.Fields.Item("field").Value
Thanks!
- Elmer M.
Message #4 by "Dave Rezoski" <daverezoski@h...> on Wed, 17 Apr 2002 16:45:31 +0000
|
|
Here's yet another way to accomplish this with VB.NET:
Dim requestColl As NameValueCollection
requestColl = Request.QueryString
Dim requestArray() As String = requestColl.AllKeys
ID = CInt(requestColl("eid"))
When using this approach, however, you must include the following line
outside of your class definition:
Imports System.Collections.Specialized
----Original Message Follows----
From: info@e...
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] Help with user control property
Date: Wed, 17 Apr 2002 08:58:05
Hello all,
I am having trouble pasing a querystring value as a property to one of my
controls. My control is set to take a value on the property ProductID. I
want the page that is calling the control to provide the ProductID value,
that will be a dynamic field, either from a database or from the URL
Querystring. For example, I would need to read the following:
http://mysite.com?id=123456
123456 is what I would like to be in the ProductID value.
I tried the different codes below and none seem to pass the value:
------------------------------------------------------------------------
<uc1:control id="mycontrol" ProductID='<%Request.QueryString("id");%>'
runat="server">
</uc1:control>
<uc1:control id="mycontrol" ProductID='<%Request.QueryString["id"];%>'
runat="server">
</uc1:control>
<uc1:control id="mycontrol" ProductID='<%# Request.QueryString["id"]%>'
runat="server">
</uc1:control>
and I also tried puting it in a variable and then adding it:
<%string strID = Request.QueryString["id"]%>
<uc1:control id="mycontrol" ProductID='<%Response.Write(strID);%>'
runat="server">
</uc1:control>
I would also appreciate it if someone can show me how to easily put a data
field value into a variable. In classic asp it was fairly easy. I tried a
few different ways in ASP.net and I cannot get it right.
I would like the euivalent to the following classic code:
Dim strField
strField = rs.Fields.Item("field").Value
Thanks!
- Elmer M.
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Message #5 by "Goh Mingkun" <mangokun@h...> on Thu, 18 Apr 2002 02:17:22
|
|
Elmer, I have tried it out, and although I got my solution to work, but I
am not sure whether it is what you want to accomplish.
Follow the steps below and see whether you can understand how it works
after that:
Create a VB Web Application.
Add a Web User Control in the same project.
In WebUserControl1, add a TextBox.
Double-click on any part of the form, and above the Page_Load event, type
this:
Public EmployeeName As String
and inside the Page_Load event, type this:
TextBox1.Text = EmployeeName
Now go back to Design View of WebForm1, and drag WebUserControl1 from
Solution Explorer onto WebForm1.
Double-click on any part of the form, and above the Page_Load event, type
this if it is not there yet:
Protected WithEvents WebUserControl11 As WebUserControl1
and inside the Page_Load event, type this:
WebUserControl11.EmployeeName = "Elmer M."
Message #6 by "Goh Mingkun" <mangokun@h...> on Thu, 18 Apr 2002 02:27:41
|
|
If you manage to see your name in the TextBox, then it is working normally.
You can of course change the string "Elmer M." to Request.QueryString
("id") or rs.Fields.Item("field").Value.
For more info,
look for 'passing values in Web Forms pages' in vs.net documentation.
|
|
 |