I have a set of similar classes (c1, c2, ...).
I would like to create a template (or a page with as much abstraction
as possible) to copy/paste, and create ASPX pages to edit
(add/update/...) these classes.
A customised page for each class, beacause there are few differences
between them
On top of this (copied) template, I would define the name of the class
I want to edit.
The following generates error, but you get the idea:
public class TemplateEdit : System.Web.UI.Page
{
protected Class1 mainObject; //replace Class1 by the Object to edit
protected string mainObjectName;
protected Type mainObjectType;
//Define main object here
mainObjectName = "Company";
mainObjectType = typeof(Class1);
//Generic code, the same on all aspx pages
this.mainObject = (mainObjectType) new Object();
this.mainObject = (mainObjectType)Session[mainObjectName];
Session[mainObjectName] = this.mainObject;
private void SubmitBtn_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
//....
} 19 1584
I am just curious what you are trying to accomplish here .. it seems alot of
the items you discuss would be better served though inheritance than
copy/paste.
example :
public class MyPageBase : Page {
protected object mainObject; //replace Class1 by the Object to edit
protected string mainObjectName;
protected Type mainObjectType;
//etc
}
then
public class MyChildPage : MyBasePage {
}
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com... I have a set of similar classes (c1, c2, ...).
I would like to create a template (or a page with as much abstraction as possible) to copy/paste, and create ASPX pages to edit (add/update/...) these classes. A customised page for each class, beacause there are few differences between them
On top of this (copied) template, I would define the name of the class I want to edit. The following generates error, but you get the idea:
public class TemplateEdit : System.Web.UI.Page { protected Class1 mainObject; //replace Class1 by the Object to edit protected string mainObjectName; protected Type mainObjectType;
//Define main object here mainObjectName = "Company"; mainObjectType = typeof(Class1);
//Generic code, the same on all aspx pages this.mainObject = (mainObjectType) new Object(); this.mainObject = (mainObjectType)Session[mainObjectName]; Session[mainObjectName] = this.mainObject;
private void SubmitBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e) { //.... }
Very well,
This is part of the solution, thank you
but that still doesn't answer my question
Suppose I have a session variable I want to cast this main object to a
specific one.
I would need to write a generic type in MyPageBase
mainObject = (mainObjectType)Session[mainObjectName]; // does not
work
can NOT be translated in the customised pages (AFAIK) into
Class1 mainObject = new (Class1);
mainObjectName = "Class1";
mainObjectType = typeof(Class1);
This line would be copy/pasted in all pages instead of in MyPageBase
I am not understanding this part of your question ... are you asking how you
can add a generic to your page base?
Cheers,
Greg Young
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com... Very well, This is part of the solution, thank you
but that still doesn't answer my question
Suppose I have a session variable I want to cast this main object to a specific one. I would need to write a generic type in MyPageBase
mainObject = (mainObjectType)Session[mainObjectName]; // does not work
can NOT be translated in the customised pages (AFAIK) into Class1 mainObject = new (Class1); mainObjectName = "Class1"; mainObjectType = typeof(Class1);
This line would be copy/pasted in all pages instead of in MyPageBase
My question is: How to write a base class?
I Opted finaly for the following 'utility' (NOT a base class) to write
in it the commong functions to all similar pages:
Page_Load
BaseIsPostBack_Pre("Company");
public class _BaseForm
{
public _BaseForm(System.Web.UI.Page page)
{
((ImageButton)page.FindControl("CancelBtn")).Attri butes.Add("onclick", "return
confirm('Are you sure?');");
}
1 - What worries me by passing the whole page as a parameter is whether
it is passed by value or by reference: What if I have a DataSet filled
later? Will it copy it too?
2 - Is there any alternative to the above?
I gave an example of that already ..
"public class MyPageBase : Page {
protected object mainObject; //replace Class1 by the Object to edit
protected string mainObjectName;
protected Type mainObjectType;
//etc
}
then
public class MyChildPage : MyBasePage {
}"
Are you needing an example of using a generic within the base class?
Cheers,
Greg Young
MVP - C#
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com... My question is: How to write a base class?
1 - System.Web.UI.Page is a reference type so it doesn't matter if you
pass it by value or reference???
2 - Couldn't your web page inherit from _BaseForm instead?
Yes just use a base class as presented ...
you can tie the event in the base and put this code in it.
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com... I Opted finaly for the following 'utility' (NOT a base class) to write in it the commong functions to all similar pages:
Page_Load BaseIsPostBack_Pre("Company");
public class _BaseForm { public _BaseForm(System.Web.UI.Page page) { ((ImageButton)page.FindControl("CancelBtn")).Attri butes.Add("onclick", "return confirm('Are you sure?');"); }
1 - What worries me by passing the whole page as a parameter is whether it is passed by value or by reference: What if I have a DataSet filled later? Will it copy it too?
2 - Is there any alternative to the above?
This should get you going, I just typed it up here quickly .. no compilation
assurances but it should be pretty close :)
public class BasePage : System.Web.UI.Page
{
private void AddJs() {
((ImageButton)this.FindControl("CancelBtn")).Attri butes.Add("onclick",
"return
confirm('Are you sure?');");
}
private void Page_Load(object sender, EventArgs e) {
this.AddJs();
}
public BasePage() {
this.Load += new System.EventHandler(this.Page_Load);
}
}
then just take your page and inherit from BasePage instead of
System.Web.UI.Page.
Cheers,
Greg Young
MVP - C#
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com... I Opted finaly for the following 'utility' (NOT a base class) to write in it the commong functions to all similar pages:
Page_Load BaseIsPostBack_Pre("Company");
public class _BaseForm { public _BaseForm(System.Web.UI.Page page) { ((ImageButton)page.FindControl("CancelBtn")).Attri butes.Add("onclick", "return confirm('Are you sure?');"); }
1 - What worries me by passing the whole page as a parameter is whether it is passed by value or by reference: What if I have a DataSet filled later? Will it copy it too?
2 - Is there any alternative to the above?
Excellent, Thank you Greg
we are getting finally somewhere
Now, to go back to my first example
I want to pass a few 'parameters' to my Base class, mainly
mName: "The Company", for display, can contain spaces
mShortName: "Company", for coding
mType: a reference to another class
Suppose for example, I want the text on the cancel button to be "Cancel
The Company"
In the pages, I would assign
mName = "The Company"
I would add somewhere in the base class:
((ImageButton)this.FindControl("CancelBtn")).Text = "Cancel " +
mName
But what if I want to use mType, for example to cast as session
variable?
page: mType = typeof(Class1);
base:
Session[mName] = this.mainObject;
this.mainObject = (mType)Session[mName]; //does NOT work
my trouble lies in the last statement
Again, thank you for your help
Make them protected variables in your base class and have the deriving class
(your page) set them in its constructor.
Cheers,
Greg Young
MVP - C#
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com... Excellent, Thank you Greg we are getting finally somewhere
Now, to go back to my first example I want to pass a few 'parameters' to my Base class, mainly mName: "The Company", for display, can contain spaces mShortName: "Company", for coding mType: a reference to another class
Suppose for example, I want the text on the cancel button to be "Cancel The Company" In the pages, I would assign mName = "The Company" I would add somewhere in the base class: ((ImageButton)this.FindControl("CancelBtn")).Text = "Cancel " + mName
But what if I want to use mType, for example to cast as session variable? page: mType = typeof(Class1); base: Session[mName] = this.mainObject; this.mainObject = (mType)Session[mName]; //does NOT work
my trouble lies in the last statement Again, thank you for your help
I am sorry I don't understand
Can you please provide me with an example to illustrate your point?
I am sorry I don't understand
Can you please provide me with an example to illustrate your point?
My problem is in this statement:
this.mainObject = (mType)Session[mName];
((ImageButton)this.FindControl ... Does NOT always find the control
_BaseForm baseForm = new _BaseForm(this);
The above case works, because I am passing the page as a parameter, and
hence 'this' contains the control
CompanyEdit : _BaseForm
does NOT work.
I even searched in 'this' recursively, but found nothing, because
root.Controls is null or empty
FindControlRecursive(this, "CancelBtn"):
private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
return root;
foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
return t;
}
return null;
}
Where are you calling it from? It depends on where in the page life cycle it
is called from whether or not things are initialized.
"Celine" <pl***@letsdothatagain.com> wrote in message
news:11**********************@q12g2000cwa.googlegr oups.com... ((ImageButton)this.FindControl ... Does NOT always find the control
_BaseForm baseForm = new _BaseForm(this); The above case works, because I am passing the page as a parameter, and hence 'this' contains the control
CompanyEdit : _BaseForm does NOT work. I even searched in 'this' recursively, but found nothing, because root.Controls is null or empty FindControlRecursive(this, "CancelBtn"):
private Control FindControlRecursive(Control root, string id) { if (root.ID == id) return root;
foreach (Control c in root.Controls) { Control t = FindControlRecursive(c, id); if (t != null) return t; } return null; }
I was calling it from the constructor,
Now it is working
Thank you
Hi there...
I'll take a course in ASP.NET, but I'm a Macintosh user, do you know if
there's a Mac version of this software, or if is a way to use it in Macintosh
Operative System (MacOS X) since this OS use Unix programation?
Thanks.
Yes there is .. it is open source and called "Mono" you can check it out
here http://www.mono-project.com/Main_Page
It works with apache through mod_mono ...
Cheers,
Greg Young
"Jaime Arturo" <Jaime Ar****@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com... Hi there...
I'll take a course in ASP.NET, but I'm a Macintosh user, do you know if there's a Mac version of this software, or if is a way to use it in Macintosh Operative System (MacOS X) since this OS use Unix programation?
Thanks.
I still failed to pass DataTypes as parameters, as in the following 3
examples:
this.mainObject = (mType)Session[mName];
this.mainObjectDt.AddMainObjectRow(this.DataSet_GU IDs_C1Row);
mainObject.UpdateMainObject(ref DataSet_GUIDs_C1DataTable)
Celine wrote: Excellent, Thank you Greg we are getting finally somewhere
Now, to go back to my first example I want to pass a few 'parameters' to my Base class, mainly mName: "The Company", for display, can contain spaces mShortName: "Company", for coding mType: a reference to another class
Suppose for example, I want the text on the cancel button to be "Cancel The Company" In the pages, I would assign mName = "The Company" I would add somewhere in the base class: ((ImageButton)this.FindControl("CancelBtn")).Text = "Cancel " + mName
But what if I want to use mType, for example to cast as session variable? page: mType = typeof(Class1); base: Session[mName] = this.mainObject; this.mainObject = (mType)Session[mName]; //does NOT work
my trouble lies in the last statement Again, thank you for your help This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Carlo Milanesi |
last post by:
Let's say I want to write the following function,
void f(const list<int> &l, const vector<int> &v) {
cout << get_second(l) << '\n';
cout << get_second(v) << '\n';
cout << get_nth(l, 2) << '\n';...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.10.2004
Hello,
As far as I understand, the generic programming basically consists
in using templates for achieving a static polymorphism of the
various code fragments, and their...
|
by: Greg Buchholz |
last post by:
/*
I've been experimenting with some generic/polytypic programs, and
I've stumbled on to a problem that I can't quite figure out. In the
program below, I'm trying to define a generic version of...
|
by: Rune Vistnes |
last post by:
Hey,
I am trying to wrap an unmanaged library in managed c++ so that I can use
this library in other .NET languages, such as C#. I've been successful for
the most part this far, but I'm having a...
|
by: steve yee |
last post by:
i think c should adapt c++ template standard, as well as namespace. if
so, c can replace c++ in many cases.
|
by: mps |
last post by:
I want to define a class that has a generic parameter that is itself a
generic class. For example, if I have a generic IQueue<Tinterface, and
class A wants to make use of a generic class that...
|
by: gary.bernstein |
last post by:
I want to call a singleton getInstance function to retrieve a
templatized object without knowing what types were used to create the
singleton object in the first call to getInstance. How can I do...
|
by: Boris |
last post by:
I have a class which should like this ideally:
generic <typename T>
public ref class ManagedClass
{
T ^managedMember;
UnmanagedClass<U*unmanagedMember;
};
I actually would like to specify...
|
by: software |
last post by:
Hello,
I am a new bee to c++/cli, here's my question: I have a template
version of a smart pointer class I can't use in my application because
I need to use it in more than one assembly. I...
|
by: puzzlecracker |
last post by:
Unlike C++, in Csharp you're only allowed to compare a generic type T
with null, if the method it's passed in not implementing
IComparable<Tor , IEquatable<T(still don't know why we need these...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
|
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...
| |