Does anyone have any easy to medium to hard examples of using web controls in web pages...???
Easy would be a good start.
Woof
Printable View
Does anyone have any easy to medium to hard examples of using web controls in web pages...???
Easy would be a good start.
Woof
Really easy:
VB Code:
Imports System Imports System.Web Imports System.Web.UI Namespace IDIOT Public Class MyComponent Inherits Control Dim _writewhat As String = "GO AWAY!" Dim _bold As Boolean = False Dim _underlined As Boolean = False Protected Overrides Sub Render(ByVal Output As HtmlTextWriter) Dim strBold As String Dim strBoldEnd As String Dim strUnderlined As String Dim strUnderlinedEnd As String strBold = IIf(Me.Bold, "<b>", "") strBoldEnd = IIf(Me.Bold, "</b>", "") strUnderlined = IIf(Me.Underlined, "<u>", "") strUnderlinedEnd = IIf(Me.Underlined, "</u>", "") Output.Write(strBold & strUnderlined & Me.WriteWhat & strUnderlinedEnd & strBoldEnd) End Sub Public Property WriteWhat() As String Get Return CType(ViewState("WriteWhat"), String) End Get Set(ByVal Value As String) ViewState("WriteWhat") = Value End Set End Property Public Property Bold() As Boolean Get Return CType(ViewState("Bold"), Boolean) End Get Set(ByVal Value As Boolean) ViewState("Bold") = Value End Set End Property Public Property Underlined() As Boolean Get Return CType(ViewState("Underlined"), Boolean) End Get Set(ByVal Value As Boolean) ViewState("Underlined") = Value End Set End Property End Class 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>
That's in a class right? Not a web control?
Errrr...whats the difference?
Mend I'd rather use <b>
than the stupid class hahahahahahahaha
Good simple example, nice name too.
Woka a web control is a class.
Oh shuttup. :)Quote:
Originally posted by jhermiz
Mend I'd rather use <b>
than the stupid class hahahahahahahaha
A web control and a class are different things...
This is code for a web contro:
What mendhak posted was a class that inherrits a control. That is not a web control.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 is alos doing is he's combines VB and HTML ouch :(
These should be seperate.
Woof
Then the class to go with it is:
VB Code:
Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Public Class HeaderWOOF Inherits UserControl Public Woof As String = "red" End Class
Woof
The only web control I use is the datalist :)
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) %>">
<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) %>">
<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>
I do not like Datalists, or repeater or grid controls.
I have opted for the mthod of XSLT :D
Works 10x better and gives you WAY more functionality and control over what happens.
Woka