Next I throw this user control onto my aspx file (using VS 2003). Then I want to set the user control variable, so I wrote the following code in .aspx.cs file:
userControl1.publicVariable="some text";
But I get compilation error which says that it cannot recognise userControl1.
I have ensured that my control is called userControl1 (e.g. the ID attribute in the HTML code is userControl1).
After throwing a user control onto an aspx file, do i need to do any thing special in the code-behind file to ensure that it can see the user control?
regardsHi there,
Please look at the code below, which is adding a usercontrol names header onto the page.
<%@. register TagPrefix="HeadC" TagName="Header" src="http://pics.10026.com/?src=~/Controls/Header.ascx"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<a name="0"></a>
<table width="770" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffff"
class="styled">
<tr>
<td><HeadC:Header id="hd1" runat="Server" EnableViewState="False" /></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td><asp:Label ID="lblContent" runat="server" CssClass="content" EnableViewState="False"></asp:Label></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><div align="center"><br>
<br>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</HTML>
In the above case user control faile was saved in a folder names controls under the root of the web site.
Hope this helps.
Hello, I suggest you visit this link:
An Extensive Examination of UserControls
regards
0 comments:
Post a Comment