473,383 Members | 1,843 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,383 software developers and data experts.

form id, this.Controls ... ?

Hi,

While writing code for creating aspx controls dynamically, I noticed some
strange (at least to me) behavior.
Look at this code;

// FreeQuery : System.Web.UI.Page
// void cmdDo_Click(...)

GridView grid = new GridView();
grid.DataSource = source;
this.Controls.Add(grid); // HERE

The last line fails during execution!
But if I type like so;

//...
form1.Controls.Add(grid);

.... where form1 is generated in FreeQuery.aspx file;

....
<form id="form1" runat="server">
....

no failure will happen.

-------------------------
So what happens?
Why does this.Controls.Add fail?
What's the difference between this and form1?
....

Could you please share your knowledge with us.

Thanks in advance.
--
======
Arman
Nov 2 '06 #1
2 2081
Hello Arman,

Because "this" has the type of "ASP._Default" and not of your form

ASHi,
AS>
ASWhile writing code for creating aspx controls dynamically, I noticed
ASsome
ASstrange (at least to me) behavior.
ASLook at this code;
AS// FreeQuery : System.Web.UI.Page
AS// void cmdDo_Click(...)
ASGridView grid = new GridView();
ASgrid.DataSource = source;
ASthis.Controls.Add(grid); // HERE
ASThe last line fails during execution!
ASBut if I type like so;
AS//...
ASform1.Controls.Add(grid);
AS... where form1 is generated in FreeQuery.aspx file;
AS>
AS...
AS<form id="form1" runat="server">
AS...
ASno failure will happen.
AS>
AS-------------------------
ASSo what happens?
ASWhy does this.Controls.Add fail?
ASWhat's the difference between this and form1?
AS...
ASCould you please share your knowledge with us.
AS>
ASThanks in advance.
AS>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 2 '06 #2
Hello Michael ,

"ASP.<yourFormName_aspx>"

mistyped first time

MNHello Arman,
MN>
MNBecause "this" has the type of "ASP._Default" and not of your form
MN>
AS>Hi,
AS>>
AS>While writing code for creating aspx controls dynamically, I
AS>noticed
AS>some
AS>strange (at least to me) behavior.
AS>Look at this code;
AS>// FreeQuery : System.Web.UI.Page
AS>// void cmdDo_Click(...)
AS>GridView grid = new GridView();
AS>grid.DataSource = source;
AS>this.Controls.Add(grid); // HERE
AS>The last line fails during execution!
AS>But if I type like so;
AS>//...
AS>form1.Controls.Add(grid);
AS>... where form1 is generated in FreeQuery.aspx file;
AS>...
AS><form id="form1" runat="server">
AS>...
AS>no failure will happen.
AS>-------------------------
AS>So what happens?
AS>Why does this.Controls.Add fail?
AS>What's the difference between this and form1?
AS>...
AS>Could you please share your knowledge with us.
AS>Thanks in advance.
AS>>
MN---
MNWBR,
MNMichael Nemtsev :: blog: http://spaces.live.com/laflour
MN"At times one remains faithful to a cause only because its opponents
MNdo not cease to be insipid." (c) Friedrich Nietzsche
MN>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 2 '06 #3

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

Similar topics

5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
7
by: Saintor | last post by:
What I do now is I put a value in the tag property, and using the form_current event, I run through all controls properties until the ones with the required tag value are met. Sound OK in theory,...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
4
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
4
by: Philip Wagenaar | last post by:
I have made a form with a tab that containts groupboxes and those contain checkboxes. When I run the application sometimes the outlining for some groupboxes are not shown, if I switch tabs and...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
19
by: Coward 9 | last post by:
HI, I saw in an example hello.aspx, there is a <form tagbeing used like <form runat="server> I search all html tag references and could NOT find "runat" attributes for <formtag. which...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.