Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2003, 04:55 AM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How use usercontrol in code behind file?

I'm a beginer of ASP.net
If I define a usercontrol in the main.aspx file like this:
[u]<% @Page Inherits="CodeBehind" Language="c#" src="code.cs" %>
<% @Register tagprefix="usercontrol" Tagname="footer" src="footer.ascx" %>
<asp:Label id="theLabel" runat="server"/>
<usercontrol:footer id="footer1" runat="server"/></u>
And i write the codebehind file(code.cs) like this:
[u]public class CodeBehind:Page
{
  public Label theLabel;
  ??;
}</u>
What should I write at the place of "??" if I what to use the usercontrol "footer" in the codebehind file?
and what should i write at the top of the codebehind file?

 
Old August 22nd, 2003, 11:01 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you have a usercontrol called "footer" than I'm going to assume it's codebehind class is "footer" so...

If you aspx code behind you should be able to do this...
Code:
public footer footer1;
Then you can use "footer1" in your codebehind methods. For any control that is defined in an ascx or aspx file (the HTML), you put a line in the codebehind to declare the corresponding control ID. Just remember not to use the "new" keyword. The code for the control in the HTML causes the control to be instantiated. You just need the control ID declared in the code behind.

Also, you should use something like this in the code behind:
Code:
protected withevents <controltype> <controlID>;
This way you get the control's events to fire in the codebehind.
(Please excuse any C# typos, I work in VB.)

------------------------
Peter
Somewhere outside
Boston, MA USA Earth





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
usercontrol in datagrid flickerslair ASP.NET 1.0 and 1.1 Basics 0 January 5th, 2006 11:59 AM
transfearing code to aspx file from vb file alyeng2000 ASP.NET 1.0 and 1.1 Professional 1 December 15th, 2003 11:12 AM
UserControl withFlexGrid dfbosse VB How-To 1 June 24th, 2003 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.