I created my first user control. Just two boxes with a colon between them to represent time. Something does not seem to be right though and I don't know what I'm doing wrong. When I drag the control onto a web page, it doesn't render correctly and instead
looks like this:
I can create the control by typing in the code mysel and, it will render when the page loads but I am not able to access its properties (i.e. I can not manipulate x.hour or x.minute) I reapplied SP1 to make sure that nothing had become corrupt but
the problem persists. Note also that I created a new "test" control just to make sure that this one had not become corrupt but it too has the same problems. Below are my ascx and aspx files. I've purposely made this as basic as possible to avoid any other
extraneous problems. I'm very frustrated and don't know why this isn't working.
ASCX
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TimeBox.ascx.vb" Inherits="Time_Entry_System.TimeBox" %>
<script runat="server">
Public Property Hour() As Integer
Set(value As Integer)
txtHour.Text = value.ToString
End Set
Get
Hour = CInt(txtHour.Text)
End Get
End Property
Public Property Minute() As Integer
Set(value As Integer)
txtMinute.Text = value.ToString
End Set
Get
Minute = CInt(txtMinute.Text)
End Get
End Property
</script>
<asp:TextBox ID="txtHour" runat="server" Width="25px"></asp:TextBox>
<b>:</b>
<asp:TextBox ID="txtMinute" runat="server" Width="25px"></asp:TextBox>
ASPX (note that the .vb page has "Imports Time_Entry_System.TimeBox" statement)
JonnyBravoII
Member
43 Points
74 Posts
Can't access public properties in code
May 14, 2012 12:29 PM|LINK
I created my first user control. Just two boxes with a colon between them to represent time. Something does not seem to be right though and I don't know what I'm doing wrong. When I drag the control onto a web page, it doesn't render correctly and instead looks like this:
<a href="~/Controls/TimeBox.ascx">~/Controls/TimeBox.ascx</a>
I can create the control by typing in the code mysel and, it will render when the page loads but I am not able to access its properties (i.e. I can not manipulate x.hour or x.minute) I reapplied SP1 to make sure that nothing had become corrupt but the problem persists. Note also that I created a new "test" control just to make sure that this one had not become corrupt but it too has the same problems. Below are my ascx and aspx files. I've purposely made this as basic as possible to avoid any other extraneous problems. I'm very frustrated and don't know why this isn't working.
ASCX
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="TimeBox.ascx.vb" Inherits="Time_Entry_System.TimeBox" %>
<script runat="server">
Public Property Hour() As Integer
Set(value As Integer)
txtHour.Text = value.ToString
End Set
Get
Hour = CInt(txtHour.Text)
End Get
End Property
Public Property Minute() As Integer
Set(value As Integer)
txtMinute.Text = value.ToString
End Set
Get
Minute = CInt(txtMinute.Text)
End Get
End Property
</script>
<asp:TextBox ID="txtHour" runat="server" Width="25px"></asp:TextBox>
<b>:</b>
<asp:TextBox ID="txtMinute" runat="server" Width="25px"></asp:TextBox>
ASPX (note that the .vb page has "Imports Time_Entry_System.TimeBox" statement)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm3.aspx.vb" Inherits="Time_Entry_System.WebForm3" %>
<%@ Register src="~/Controls/TimeBox.ascx" tagname="TimeBox" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc1:TimeBox ID="testcontrol" runat="server" Hour="4" and Minute="0" />
</form>
</body>
</html>