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)
{
//....
}
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:1146813018.2...@j73g2000cwa.googlegroups.com...
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
Cheers,
Greg Young
"Celine" <pl...@letsdothatagain.com> wrote in message
news:1147159933.6...@v46g2000cwv.googlegroups.com...
Page_Load
BaseIsPostBack_Pre("Company");
public class _BaseForm
{
public _BaseForm(System.Web.UI.Page page)
{
((ImageButton)page.FindControl("CancelBtn")).Attributes.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?
"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:1147242123.0...@y43g2000cwc.googlegroups.com...
2 - Couldn't your web page inherit from _BaseForm instead?
you can tie the event in the base and put this code in it.
"Celine" <pl...@letsdothatagain.com> wrote in message
news:1147242609....@v46g2000cwv.googlegroups.com...
public class BasePage : System.Web.UI.Page
{
private void AddJs() {
((ImageButton)this.FindControl("CancelBtn")).Attributes.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:1147242609....@v46g2000cwv.googlegroups.com...
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
Cheers,
Greg Young
MVP - C#
"Celine" <pl...@letsdothatagain.com> wrote in message
news:1147249429.8...@e56g2000cwe.googlegroups.com...
My problem is in this statement:
this.mainObject = (mType)Session[mName];
_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;
}
"Celine" <pl...@letsdothatagain.com> wrote in message
news:1147424560.8...@q12g2000cwa.googlegroups.com...
Thank you
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.
It works with apache through mod_mono ...
Cheers,
Greg Young
"Jaime Arturo" <Jaime Art...@discussions.microsoft.com> wrote in message
news:BF7CC023-F94D-42D1...@microsoft.com...
See the big picture here:
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/e0859715a73167b0/349184b7d4ba2232?tvc=2&hl=en#349184b7d4ba2232
Perhaps you need:
this.mainObject = (_BaseForm)Session[mName];
As long as your base form implements the required methods, and of
course this.mainObject is declared of type _BaseForm.
Otherwise interface might help, but abstract class is still better.