CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!
Free 3 Months



Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 7/27/2004 5:43:05 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 4 Views: 27 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
5 Items, 1 Pages 1 |< << Go >> >|
Ashleigh
Asp.Net User
Custom Controls - Referencing from the code behind file7/27/2004 5:43:05 AM

0/0

Hey,

I have a custom control, with a public property.

I want to change this property from the codebehind file.

When I create a textbox, I can say


protected TextBox myTxtBx;

myTxtBx.Text="hello";


With my custom control, if I declare it in the same way, it says it doesn't recognise the object.

ie


protected myTextBox myTxtBx;

myTxtBx.Text="hello";


myTextBox being my custom control, how do I reference/declare the custom control instance so I can start editing it's properties in the codebehind file?

Thanks,
-Ashleigh
mhp
Asp.Net User
Re: Custom Controls - Referencing from the code behind file7/27/2004 3:07:24 PM

0/0

Have you droped your custom control on ASPX page? The code you wrote doen't create the instance of myTextBox. In VB you need something like following:
protected myTxtBx as myTextBox

myTxtBx = new myTextBox
myTxtBx.Text="hello"
Page.Controls.Add(myTxtBx)
For further information see Adding Controls to a Web Forms Page Programmatically.
-MHP
llangleyben
Asp.Net User
Re: Custom Controls - Referencing from the code behind file7/27/2004 3:27:40 PM

0/0

You have to add reference to assembly with customcontrol, you are using and "using" statement to access customcontrol namespace. VS add reference for you in the moment you drop control from toolbox on design surface. You have to add "using" statement (or use full type names) manually.
Leon Langleyben

MCSD, ASP.NET MVP

Blog
Ashleigh
Asp.Net User
Re: Custom Controls - Referencing from the code behind file7/27/2004 4:15:52 PM

0/0

Hey,

what is the using declaration? (I know what you mean, but, my problem is:)

My control is an ascx file. I havn't compiled it (and am not sure how to compile it). I'm not sure where to declare the namespace in a custom control either. Also, I may be confusing the issue. I'm not sure of the difference between a custom control and a user control.

Could you give me a really basic example, or a link to a basic tutorial on it? (I've been searching and searching, and everything I find is just about programmatically including the controls, arg, lol).

Thanks a lot for your help.

-Ashleigh

(Infact, here is a very simplified version of my code)

ascx control

<%@ Control Language="c#" %>
<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.Web.Security" %>
<%@ import Namespace="System.Configuration" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Web" %>

<script runat="server">

public class AdvTextBox : System.Web.UI.UserControl
{

}

public string Fish
{
get {return "hello";}
set {Response.Write(value);}
}

private void Page_Load(object sender, EventArgs e)
{

}
</script>



ASPX Page

<%@ Page Src="test.cs" Inherits="test" ValidateRequest="false" Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="myControls" TagName="AdvTextBox" Src="AdvTextBox.ascx" %>
<html>
<head>
<title>Advanced TextBox</title>

</script>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
<myControls:AdvTextBox id="mcHeader" strCode="jHeader" width="400" height="600" Runat="Server"/>

</form>
</body>
</html>


CODEBEHIND for ASPX (I dont' know what to do in here, I'll paste my latest attempt)

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Data;

public class test: Page {

protected TextBox txtBox;
//protected Control myControl;
protected UserControl mcHeader;
//protected AdvTextBox mcHeader;
/* PAGE LOAD */
void Page_Load(Object sender , EventArgs e)
{
mcHeader = (UserControl)LoadControl("advTextBox.ascx");
//mcHeader.InitializeAsUserControl(this);
mcHeader.Fish="hello"; //<--Error occurs on this line
if(!IsPostBack)
{
}

}
}



Compiler Error Message:'System.Web.UI.UserControl' does not contain a definition for 'Fish'

Thanks again
Ashleigh
Asp.Net User
Re: Custom Controls - Referencing from the code behind file8/5/2004 5:58:04 PM

0/0

Hey hey,

Yea, I dont' use VS.NET or anything, so my prob was how to do all that dll stuff, but I found some useful tutorials about how to compile ascx files etc, thanks a lot for your help ;-)

-Ashleigh
5 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Building Web Applications with C# and .NET: A Complete Reference Authors: Dudley W. Gill, Pages: 718, Published: 2002
Professional Web Parts and Custom Controls with ASP.NET 2.0 Authors: Peter Vogel, Pages: 449, Published: 2005
ASP.NET 2.0 Website Programming: Problem-design-solution Authors: Marco Bellinaso, Pages: 576, Published: 2006
Professional ASP.NET 1.1 Authors: Alex Homer, Dave Sussman, Rob Howard, Brian Francis, Karli Watson, Richard Anderson, Pages: 1337, Published: 2004
Expert F# Authors: Don Syme, Adam Granicz, Antonio Cisternino, Pages: 609, Published: 2007
Beginning ASP.NET 1.1 with VB.NET 2003 Authors: Chris Ullman, John Kauffman, Chris Hart, David Sussman, Pages: 888, Published: 2003
Beginning ASP.NET 1.1 with Visual C# .NET 2003 Authors: Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry, Pages: 888, Published: 2004
MCAD Developing and Implementing Web Applications with Microsoft Visual C#(TM) . NET and Microsoft Visual Studio(R) . NET Exam Cram 2 (Exam Cram 70-315): Exam Cram 2, McAd Exam 70-315 Authors: Kirk Hausman, Amit Kalani, Ed Tittel, Pages: 600, Published: 2003
Developing Microsoft ASP.NET Server Controls and Components Authors: Nikhil Kothari, Vandana Datye, Pages: 689, Published: 2002
Pro ASP. Net 3. 5 Server Controls and AJAX Components Authors: Rob Cameron, Dale Michalk, Pages: 740, Published: 2008

Web:
Tip/Trick: How to Register User Controls and Custom Controls in ... If you declare the control type/name in your code-behind file in a VS 2005 ..... You can do this by using the "~" syntax when referencing the controls from ...
Try it: Create a custom WPF control For more information about custom controls, including XAML and code .... In the top of the code-behind file (Window1.xaml.cs), add a reference to the System ...
15 Seconds : Creating a Web Custom Control Conrad Jalali shows how to build Web custom controls by creating one that ... ASPX page and the C# code-behind file every time that a car maker was added, ...
CodeProject: Convert the web user controls into custom controls in ... I am doing this because in update mode only files of code behind will be .... In Page_load of user control if i reference any of the controls i get the ...
Codebehind Files in ASP.NET MVC are Evil : Steve Smith's Blog Now you can reference Customer in a strongly typed fashion from your View's ASPX ... codebehind files may be important for interacting with custom controls. ...
Creating a Custom Control - WPF Custom Controls - developerFusion ... Figure 1: Visual Studio 2008 Template for creating WPF custom controls. Visual Studio creates a code behind file for you (in this case—AlarmClockControl.cs) ...
Learning ASP.NET for the ASP Developer - Part 3 | O'Reilly Media Dec 6, 2004 ... NET allows you to define your own markup tags or custom controls. .... Since the code-behind file is a totally separate file from the ...
Assigning Custom Server Control Parameter/Property From Code ... If I use the code-behind file, I think I was able to locate the control by ..... I forgot to do 'add reference' to the server control (or do I need to?). ...
Creating Web Custom Controls with Visual Studio.NET, Part I ... There are principally three ways of creating web custom controls and we're ... the control through the script block of the page (or the code-behind file if ...
DotNetSlackers: Codebehind Files in ASP.NET MVC are Evil Sep 17, 2008 ... Tomorrow (as in, with some future release, I'm guessing), codebehind files may be important for interacting with custom controls. ...

Videos:
GeoServer and Architectures of Participation for Geospatial Information Google TechTalks August 23, 2006 Chris Holmes ABSTRACT This talk will introduce GeoServer, an open source server to publish and edit geospatial dat...
django: Web Development for Perfectionists with Deadlines Google TechTalks April 26, 2006 Jacob Kaplan-Moss ABSTRACT Django is one of the premier web frameworks for Python, and is often compared to Ruby-on...
Long Beach City Council Meeting Long Beach City Council Meeting




Search This Site:










genuinely free asp.net web hosting?

dropdownlists &amp; databases

getting connection string from web.config in a control dll

asp.net and domain host pointing

custom controls where view state may not need enabled.

support validation

ghosting error with user controls

custom controls and vs.net designer ...

why does this default to false????

need help with using out parameter

how to config ftp for website?

is it just me

customizing a dropdownlist

creating template datagrid column dynamically work just for last row

system.web.ui.design.controldesigner ????

adding child controls to a custom control

getting the collection out of the dropdownlist

how can i convert a page aspx in a custom control?

dynamic control

super advanced custom control question

appearance of composite control

customer datagrid user control

dropdownlist inharited web custom control

prevent drop of control in a page

modeless dialog in asp.net

adding design time uitypeeditor for font

postback displeasures

comparing vwdhosting with other hosting companies

hosting with mssql 2005 reporting service?

debugging client side !!

  Privacy | Contact Us
All Times Are GMT