Saturday, March 24, 2012

Simple custom Web control

Hello, all. I'm trying to create a Web control that will have a small
graphic and a label that I can change on page load. However, I'm having no
luck accessing the subHeadingText property to set it on the page load event
server-side. Here's the code for the custom control's HTML:
----
--
<%@dotnet.itags.org. Control Language="vb" AutoEventWireup="false"
Codebehind="pageTitle.ascx.vb" Inherits="WebApplication1.pageTitle"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<%
Public Property subHeadingText() As String
Get
Return lblPageTitle.Text
End Get
Set(ByVal Value As String)
lblPageTitle.Text = Value.ToString()
End Set
End Property
%>
<div class="subheading">
<asp:Image id="Image1" runat="server"
ImageUrl="global/images/mis415logo2.JPG"></asp:Image>
<div id="pnlPageTitle" class="subHeadingText">
<asp:Label id="lblPageTitle" runat="server">Label</asp:Label>
</div>
</div>
----
Here's the code at the top of the form that uses the control:
<%@dotnet.itags.org. Register TagPrefix="uc1" TagName="pageTitle" src="http://pics.10026.com/?src=pageTitle.ascx" %>
----
And here's the code to instantiate an object of that type in the code-behind
page:
Protected pageTitle1 As pageTitle
----
In the Page_Load sub, I try to access pageTitle1's subHeadingText, and it
doesn't exist when I type the "." Any ideas? Thanks.I think I know what I did wrong: I put the property declaration code toward
the top of the ascx page, and it needed to be in the ascx.vb's class code.
"dw" <cougarmana_NOSPAM@.uncw.edu> wrote in message
news:eA5ft7dnEHA.3464@.tk2msftngp13.phx.gbl...
> Hello, all. I'm trying to create a Web control that will have a small
> graphic and a label that I can change on page load. However, I'm having no
> luck accessing the subHeadingText property to set it on the page load
event
> server-side. Here's the code for the custom control's HTML:
> ----
--
> --
> <%@. Control Language="vb" AutoEventWireup="false"
> Codebehind="pageTitle.ascx.vb" Inherits="WebApplication1.pageTitle"
> TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
> <%
> Public Property subHeadingText() As String
> Get
> Return lblPageTitle.Text
> End Get
> Set(ByVal Value As String)
> lblPageTitle.Text = Value.ToString()
> End Set
> End Property
> %>
> <div class="subheading">
> <asp:Image id="Image1" runat="server"
> ImageUrl="global/images/mis415logo2.JPG"></asp:Image>
> <div id="pnlPageTitle" class="subHeadingText">
> <asp:Label id="lblPageTitle" runat="server">Label</asp:Label>
> </div>
> </div>
> ----
> Here's the code at the top of the form that uses the control:
> <%@. Register TagPrefix="uc1" TagName="pageTitle" src="http://pics.10026.com/?src=pageTitle.ascx" %>
> ----
> And here's the code to instantiate an object of that type in the
code-behind
> page:
> Protected pageTitle1 As pageTitle
> ----
> In the Page_Load sub, I try to access pageTitle1's subHeadingText, and it
> doesn't exist when I type the "." Any ideas? Thanks.
>

0 comments:

Post a Comment