Results 1 to 10 of 10

Thread: ASP.NET web control..need examples????

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Resolved ASP.NET web control..need examples????

    Does anyone have any easy to medium to hard examples of using web controls in web pages...???

    Easy would be a good start.

    Woof

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Really easy:

    VB Code:
    1. Imports System
    2. Imports System.Web
    3. Imports System.Web.UI
    4.  
    5.  
    6.  
    7. Namespace IDIOT
    8.  
    9. Public Class MyComponent
    10.         Inherits Control
    11.  
    12.  
    13.         Dim _writewhat As String = "GO AWAY!"
    14.         Dim _bold As Boolean = False
    15.         Dim _underlined As Boolean = False
    16.  
    17.  
    18.  
    19.         Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
    20.             Dim strBold As String
    21.             Dim strBoldEnd As String
    22.             Dim strUnderlined As String
    23.             Dim strUnderlinedEnd As String
    24.  
    25.  
    26.             strBold = IIf(Me.Bold, "<b>", "")
    27.             strBoldEnd = IIf(Me.Bold, "</b>", "")
    28.  
    29.  
    30.             strUnderlined = IIf(Me.Underlined, "<u>", "")
    31.             strUnderlinedEnd = IIf(Me.Underlined, "</u>", "")
    32.  
    33.  
    34.  
    35.             Output.Write(strBold & strUnderlined & Me.WriteWhat & strUnderlinedEnd & strBoldEnd)
    36.         End Sub
    37.  
    38.         Public Property WriteWhat() As String
    39.             Get
    40.                 Return CType(ViewState("WriteWhat"), String)
    41.  
    42.             End Get
    43.             Set(ByVal Value As String)
    44.                 ViewState("WriteWhat") = Value
    45.             End Set
    46.         End Property
    47.         Public Property Bold() As Boolean
    48.             Get
    49.                 Return CType(ViewState("Bold"), Boolean)
    50.             End Get
    51.             Set(ByVal Value As Boolean)
    52.                 ViewState("Bold") = Value
    53.             End Set
    54.         End Property
    55.  
    56.         Public Property Underlined() As Boolean
    57.             Get
    58.                 Return CType(ViewState("Underlined"), Boolean)
    59.             End Get
    60.             Set(ByVal Value As Boolean)
    61.                 ViewState("Underlined") = Value
    62.             End Set
    63.         End Property
    64.  
    65.  
    66.  
    67. End Class
    68.  
    69. End Namespace

    Usage:

    Code:
    <%@ Register TagPrefix="idt" Namespace="WebDataApplicationTest.IDIOT" Assembly="WebDataApplicationTest" %>
    
    idt:mycomponent id="MyComponent1" runat="server" WriteWhat="ppppp" EnableViewState="True" Bold="True"></idt:mycomponent>

  3. #3

  4. #4
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Mend I'd rather use <b>
    than the stupid class hahahahahahahaha

    Good simple example, nice name too.

    Woka a web control is a class.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by jhermiz
    Mend I'd rather use <b>
    than the stupid class hahahahahahahaha
    Oh shuttup.

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    A web control and a class are different things...
    This is code for a web contro:
    Code:
    <%@ Control Language="vb" AutoEventWireup="false" Codebehind="HeaderCtl.ascx.vb" Inherits="MyDemoSite.HeaderWOOF" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    <table width="100%" bgColor="<%=Woof%>">
    	<tr>
    		<td>
    			<h2>Wokas Forums</h2>
    			<i>Woof on those growling fishes</i>
    			<br>
    			<b></b>
    		</td>
    	</tr>
    	<tr>
    		<td><asp:label id="lblDate" Runat="server"></asp:label></td>
    	</tr>
    </table>
    What mendhak posted was a class that inherrits a control. That is not a web control.

    What Mendhak is alos doing is he's combines VB and HTML ouch
    These should be seperate.

    Woof

  7. #7

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Then the class to go with it is:
    VB Code:
    1. Imports System
    2. Imports System.Web.UI
    3. Imports System.Web.UI.WebControls
    4.  
    5. Public Class HeaderWOOF
    6.     Inherits UserControl
    7.  
    8.     Public Woof As String = "red"
    9.  
    10. End Class

    Woof

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    The only web control I use is the datalist
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Code:
    		<form id="Form1" method="post">
    			<asp:datalist id="DataList1" runat="server" Height="20px" Width="100%">
    				<HeaderTemplate>
    					<font face="Verdana" size="2">Displaying results :
    						<%= intLowerBound %>
    						to
    						<%= intUpperBound %>
    						of
    						<%= intTotalRecords %>
    					</font>
    					<br>
    					<% If blnMoreThanOnePage Then %>
    						<font face="Verdana" size="2">Jump to page :
    							<%= strPageNumberArray %>
    						</font>
    						<br>
    					<% End If %>
    					<TABLE cellSpacing="3" cellPadding="1" width="100%" border="0">
    						<TR>
    							<TD align="left" width="52%"><FONT face="Verdana" size="2">Description<BR>
    									Manufacturer</FONT></TD>
    							<TD align="left" width="15%"><FONT face="Verdana" size="2">SAP #<BR>
    									Manufacturer #</FONT></TD>
    							<TD align="left" width="10%"><FONT face="Verdana" size="2">Details</FONT></TD>
    							<TD align="left" width="10%"><FONT face="Verdana" size="2">Price</FONT></TD>
    							<TD align="left" width="5%"><FONT face="Verdana" size="2">Stock</FONT></TD>
    							<TD align="left" width="8%"><FONT face="Verdana" size="2">Buy</FONT></TD>
    						</TR>
    						<TR>
    							<TD align="left" width="100%" colSpan="6">
    								<HR noShade SIZE="1">
    							</TD>
    						</TR>
    				</HeaderTemplate>
    				<FooterTemplate>
    					</TABLE>
    				</FooterTemplate>
    				<ItemTemplate>
    					<TR>
    						<INPUT id="txtStock<%# Container.DataItem(0) %>" type=hidden value="<%# Container.DataItem(6) %>" name="txtStock<%# Container.DataItem(0) %>" style="myTextBoxSmall">
    						<TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><a href="ProductDetails.aspx?strSAPCode=<%# Container.DataItem(0) %>" target="" onMouseover="setStatusWindowText('View details of SAP Code : <%# Container.DataItem(0) %>');return true;" onMouseout="setStatusWindowText('');return true;"><%# Container.DataItem(2) %></a><BR>
    								<%# Container.DataItem(8) %>
    								-
    								<%# Container.DataItem(9) %>
    							</FONT>
    						</TD>
    						<TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><%# Container.DataItem(0) %><BR>
    								<%# Container.DataItem(5) %>
    							</FONT>
    						</TD>
    						<TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><a href="<%# Container.DataItem(3) %>" target=_new>details</a></FONT></TD>
    						<TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><%# Container.DataItem(4) %></FONT></TD>
    						<!-- <TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><%# Container.DataItem(6) %></FONT></TD> -->
    						<TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><a href="javascript:updateStock('<%# Container.DataItem(0) %>');"><%# Container.DataItem(6) %></a></FONT></TD>
    						<TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"> <INPUT class=myTextBoxSmall type=text size=5 name="txtAdd<%# Container.DataItem(0) %>" id="txtAdd<%# Container.DataItem(0) %>">&nbsp;
    								<A onmouseover="setStatusWindowText('Add <%# Container.DataItem(0) %> to your shopping cart');return true;" onmouseout="setStatusWindowText('');return true;" href="javascript:addToCart('<%# Container.DataItem(0) %>', document.all.item('txtAdd<%# Container.DataItem(0) %>').value, document.all.item('txtStock<%# Container.DataItem(0) %>').value, false)">
    									Buy</A></FONT></TD>
    					</TR>
    				</ItemTemplate>
    				<AlternatingItemTemplate>
    					<TR>
    						<INPUT id="txtStock<%# Container.DataItem(0)%>" type=hidden value="<%# Container.DataItem(6) %>" name="txtStock<%# Container.DataItem(0) %>"><TD bgcolor="#E1E1E1" valign="top"><FONT face="Verdana" size="1"><a href="ProductDetails.aspx?strSAPCode=<%# Container.DataItem(0) %>" target="" onMouseover="setStatusWindowText('View details of SAP Code : <%# Container.DataItem(0) %>');return true;" onMouseout="setStatusWindowText('');return true;"><%# Container.DataItem(2) %></a><BR>
    								<%# Container.DataItem(8) %>
    								-
    								<%# Container.DataItem(9) %>
    							</FONT>
    						</TD>
    						<TD bgcolor="#E1E1E1" valign="top"><FONT face="Verdana" size="1"><%# Container.DataItem(0) %><BR>
    								<%# Container.DataItem(5) %>
    							</FONT>
    						</TD>
    						<TD bgcolor="#E1E1E1" valign="top"><FONT face="Verdana" size="1"><a href="<%# Container.DataItem(3) %>" target=_new>details</a></FONT></TD>
    						<TD bgcolor="#E1E1E1" valign="top"><FONT face="Verdana" size="1"><%# Container.DataItem(4) %></FONT></TD>
    						<!-- <TD bgcolor="#F0F0F0" valign="top"><FONT face="Verdana" size="1"><%# Container.DataItem(6) %></FONT></TD> -->
    						<TD bgcolor="#E1E1E1" valign="top"><FONT face="Verdana" size="1"><a href="javascript:updateStock('<%# Container.DataItem(0) %>');"><%# Container.DataItem(6) %></a></FONT></TD>
    						<TD bgcolor="#E1E1E1" valign="top"><FONT face="Verdana" size="1"> <INPUT class=myTextBoxSmall type=text size=5 name="txtAdd<%# Container.DataItem(0) %>" id="txtAdd<%# Container.DataItem(0) %>">&nbsp;
    								<A onmouseover="setStatusWindowText('Add <%# Container.DataItem(0) %> to your shopping cart');return true;" onmouseout="setStatusWindowText('');return true;" href="javascript:addToCart('<%# Container.DataItem(0) %>', document.all.item('txtAdd<%# Container.DataItem(0) %>').value, document.all.item('txtStock<%# Container.DataItem(0) %>').value, false)">
    									Buy</A></FONT></TD>
    					</TR>
    				</AlternatingItemTemplate>
    			</asp:datalist></form>
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  10. #10

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    I do not like Datalists, or repeater or grid controls.
    I have opted for the mthod of XSLT

    Works 10x better and gives you WAY more functionality and control over what happens.

    Woka

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width