473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access public property from my ascx control !

Hi,
Dragging & Dropping my ascx control in my aspx page, I just wanna know how I
can access its properties when validating the form ?
The control is composed of 4 controls (2 txtbox and 2 dropdown : Address,
ZipCode, Country & City).

In fact, when, in my code, I try "this.MyControlId".... it does not exist.

Thks for help.


Nov 19 '05 #1
3 12330
Hi Mick!

This is known thing in Visual Studio .NET.
But first: If you want to access control properties on ASCX, the best way is
to publish them as "public property" of ASCX class (basicaly you write a
wrapper around control properties).

When you drag your ASCX on ASPX form, Visual Studio .NET "forgets" to
declare instance variables in codebehind pages, so you have to do it "by
hand". If your ASCX id is "MyControlID", you write at codebehind class
something like:
protected MyAscxControl MyControlID

runtime environment of ASPX will coretly instatiate object, and now you can
use it in your code.

Dusan

"Mick" <sa****@libertysurf.fr> wrote in message
news:41**********************@news.free.fr...
Hi,
Dragging & Dropping my ascx control in my aspx page, I just wanna know how
I
can access its properties when validating the form ?
The control is composed of 4 controls (2 txtbox and 2 dropdown : Address,
ZipCode, Country & City).

In fact, when, in my code, I try "this.MyControlId".... it does not exist.

Thks for help.



Nov 19 '05 #2
Hi Mick,

Check your code behind, where the controls are defined as protected members
of your class. You probably need to add a line that declares your control
in your source code.

In C# this would look something like;

protected System.Web.UI.WebControls.Table tblRequest;
protected MyControl MyControl1;

That will make it possible to access your control's properties and methods
from your source.

Also, I'm fairly certain that you will only be able to access properties and
methods that you've defined. I don't recall a way to directly access the
embedded controls, though there might be a Controls collection that serves
this purpose. Otherwise you'll need to define properties and methods in
your User Control that provide access to the specific properties and methods
you want to expose. E.g.

public string Text1
{
get { return TextBox1.Text; }
set { TextBox1.Text = value; }
}

public string Text2
{
get { return TextBox2.Text; }
set { TextBox2.Text = value; }
}

And so on...

/// M
"Mick" <sa****@libertysurf.fr> wrote in message
news:41**********************@news.free.fr...
Hi,
Dragging & Dropping my ascx control in my aspx page, I just wanna know how I can access its properties when validating the form ?
The control is composed of 4 controls (2 txtbox and 2 dropdown : Address,
ZipCode, Country & City).

In fact, when, in my code, I try "this.MyControlId".... it does not exist.

Thks for help.

Nov 19 '05 #3
Thks for help ^^

"MWells" <outbound__at_sygnal.com> a écrit dans le message de
news:us**************@TK2MSFTNGP12.phx.gbl...
Hi Mick,

Check your code behind, where the controls are defined as protected members of your class. You probably need to add a line that declares your control
in your source code.

In C# this would look something like;

protected System.Web.UI.WebControls.Table tblRequest;
protected MyControl MyControl1;

That will make it possible to access your control's properties and methods
from your source.

Also, I'm fairly certain that you will only be able to access properties and methods that you've defined. I don't recall a way to directly access the
embedded controls, though there might be a Controls collection that serves
this purpose. Otherwise you'll need to define properties and methods in
your User Control that provide access to the specific properties and methods you want to expose. E.g.

public string Text1
{
get { return TextBox1.Text; }
set { TextBox1.Text = value; }
}

public string Text2
{
get { return TextBox2.Text; }
set { TextBox2.Text = value; }
}

And so on...

/// M
"Mick" <sa****@libertysurf.fr> wrote in message
news:41**********************@news.free.fr...
Hi,
Dragging & Dropping my ascx control in my aspx page, I just wanna know how
I
can access its properties when validating the form ?
The control is composed of 4 controls (2 txtbox and 2 dropdown :

Address, ZipCode, Country & City).

In fact, when, in my code, I try "this.MyControlId".... it does not exist.
Thks for help.


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: adiel | last post by:
Hello, I am trying to access the properties and methods from a user control within the code-behind file for a webform but I am receiving the message: Name 'MenuBar1' is not declared It does...
6
by: Davids | last post by:
having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1") of the page, so I created an ascx file with the DataList and Register...
5
by: djscratchnsniffing | last post by:
i know you can access an ascx's properties/methods from an aspx file. Let's say you have an aspx file with two code-behind files(ascx files). Can you access one of the ascx file's...
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
0
by: ASP Developer | last post by:
I created a very simple user control that has one dropdownlist. I bind the dropdownlist to database results on load in an ascx file. I would like to do be able to change the selectedindex from...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
1
by: =?Utf-8?B?Tmltcm9kIFJvdG5lcg==?= | last post by:
Hi, I built a web control wich has text box and public property that set or get the text value of that text box. when i try to access that property i got error: "Object reference not set to an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.