UserControl.Request Property
.NET Framework 4
Gets the HttpRequest object for the current Web request.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.Web.HttpRequestThe HttpRequest object associated with the Page that contains the UserControl instance.
The following example uses the Request property to obtain the physical path of the user control. With an ID property set to myControl, the user control's location is obtained by a containing page or user control using the myControl.Request.Path syntax.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
wucViewProduct (codebehind) | Labo4
Imports StateManagement.BL
Partial Class wuc_ViewProduct
Inherits System.Web.UI.UserControl
Private _productID As String
Private _aantal As String
Public Property ProductID() As String
Get
If Not Me.ViewState("ProductID") Is Nothing Then
Return Me.ViewState("ProductID")
Else
Return 0
End If
End Get
Set(ByVal value As String)
Me.ViewState("ProductID") = value
lblProduct.Text = value
_productID = value
End Set
End Property
Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
If e.CommandName = "Order" Then
'Dim cart As New StateManagement.BL.Cart
Dim prod As New Product
prod = Product.GetProduct(ProductID)
Dim ci As New StateManagement.BL.CartItem
ci.Product = prod
ci.Quantity = sender.FindControl("txtAantalProducten").Text.ToString
ci.Id = ProductID
Me.Session("cart").Add(ci)
Response.Redirect("Default.aspx")
FindControl("DetailsView1").DataBind()
End If
End Sub
End Class
- 9/9/2011
- Dillon Bergkamp
wucViewProduct | Labo4
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ViewProduct.ascx.vb" Inherits="wuc_ViewProduct" %>
<asp:Label ID="lblProduct" runat="server" Visible="false"></asp:Label>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="325px"
AutoGenerateRows="False" DataSourceID="ProductDS">
<Fields>
<asp:BoundField DataField="Name" HeaderText="Product" SortExpression="Name" />
<asp:ImageField HeaderText="" DataImageUrlField="ProductID" DataImageUrlFormatString="~\..\helper\CreateImage.ashx?pID={0}">
</asp:ImageField>
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="Price" HeaderText="Best Price" SortExpression="Price" DataFormatString="{0:c}"/>
<asp:TemplateField HeaderText="To be ordered">
<ItemTemplate>
<asp:TextBox ID="txtAantalProducten" runat="server" ControlToValidate="txtAantalProducten"></asp:TextBox>
<asp:RangeValidator ID="rvRangeProducten" runat="server" ErrorMessage="Geef een aantal in tussen 1 en 10." MinimumValue="1" MaximumValue="10" Type="Integer" ControlToValidate="txtAantalProducten" ValidationGroup="order"></asp:RangeValidator>
<asp:RequiredFieldValidator ID="rfvProducten" runat="server" ErrorMessage="Geef een aantal op dat u wilt bestellen" ControlToValidate="txtAantalProducten" ValidationGroup="order"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField Text="Click here to add these to my orderbook!" CausesValidation="true" CommandName="Order" ValidationGroup="order" />
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ProductDS" runat="server" SelectMethod="GetProduct"
TypeName="StateManagement.BL.Product">
<SelectParameters>
<asp:ControlParameter ControlID="lblProduct" Name="productID"
PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:Label ID="lblProduct" runat="server" Visible="false"></asp:Label>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="325px"
AutoGenerateRows="False" DataSourceID="ProductDS">
<Fields>
<asp:BoundField DataField="Name" HeaderText="Product" SortExpression="Name" />
<asp:ImageField HeaderText="" DataImageUrlField="ProductID" DataImageUrlFormatString="~\..\helper\CreateImage.ashx?pID={0}">
</asp:ImageField>
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="Price" HeaderText="Best Price" SortExpression="Price" DataFormatString="{0:c}"/>
<asp:TemplateField HeaderText="To be ordered">
<ItemTemplate>
<asp:TextBox ID="txtAantalProducten" runat="server" ControlToValidate="txtAantalProducten"></asp:TextBox>
<asp:RangeValidator ID="rvRangeProducten" runat="server" ErrorMessage="Geef een aantal in tussen 1 en 10." MinimumValue="1" MaximumValue="10" Type="Integer" ControlToValidate="txtAantalProducten" ValidationGroup="order"></asp:RangeValidator>
<asp:RequiredFieldValidator ID="rfvProducten" runat="server" ErrorMessage="Geef een aantal op dat u wilt bestellen" ControlToValidate="txtAantalProducten" ValidationGroup="order"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField Text="Click here to add these to my orderbook!" CausesValidation="true" CommandName="Order" ValidationGroup="order" />
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ProductDS" runat="server" SelectMethod="GetProduct"
TypeName="StateManagement.BL.Product">
<SelectParameters>
<asp:ControlParameter ControlID="lblProduct" Name="productID"
PropertyName="Text" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
- 9/9/2011
- Dillon Bergkamp
wucViewCart (codebehind) | Labo4
Partial Class wuc_ViewCart
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cart As StateManagement.BL.Cart
cart = Me.Session("cart")
lblTotal.Text = String.Format("{0:c}", StateManagement.BL.Cart.Total)
End Sub
Protected Sub ListView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewDeletedEventArgs) Handles ListView1.ItemDeleted
lblTotal.Text = String.Format("{0:c}", StateManagement.BL.Cart.Total)
End Sub
End Class
- 9/9/2011
- Dillon Bergkamp
wucViewCart | Labo4
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ViewCart.ascx.vb" Inherits="wuc_ViewCart" %>
<asp:ListView ID="ListView1" runat="server" DataSourceID="CartDS">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<%# Eval("Product.Name") & " " & Eval("Quantity") & " " & Eval("Subtotal")%>
<asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="delete"/><br />
</ItemTemplate>
</asp:ListView>
<asp:Label ID="lblTotal" runat="server" ></asp:Label>
<asp:ObjectDataSource ID="CartDS" runat="server" SelectMethod="GetCart"
TypeName="StateManagement.BL.Cart" DeleteMethod="Remove">
<DeleteParameters>
<asp:Parameter Name="removeCartItem" Type="Object" />
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
<asp:ListView ID="ListView1" runat="server" DataSourceID="CartDS">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<%# Eval("Product.Name") & " " & Eval("Quantity") & " " & Eval("Subtotal")%>
<asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="delete"/><br />
</ItemTemplate>
</asp:ListView>
<asp:Label ID="lblTotal" runat="server" ></asp:Label>
<asp:ObjectDataSource ID="CartDS" runat="server" SelectMethod="GetCart"
TypeName="StateManagement.BL.Cart" DeleteMethod="Remove">
<DeleteParameters>
<asp:Parameter Name="removeCartItem" Type="Object" />
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
- 9/9/2011
- Dillon Bergkamp