ASP.NET通用模板 [英] ASP.NET Generic template
问题描述
我有一组类似的类(c1,c2,...)。
我想创建一个模板(或一个具有尽可能多抽象的页面>
尽可能)复制/粘贴,并创建ASPX页面进行编辑
(添加/更新/ ...)这些类。
自定义页面对于每个班级,因为他们之间几乎没有差异
除了这个(复制的)模板之外,我还要定义班级的名称。 />
我想编辑。
以下生成错误,但你明白了:
public class TemplateEdit:System.Web.UI.Page
{
protected Class1 mainObject; //用Object替换Class1来编辑
protected string mainObjectName;
protected类型mainObjectType;
//定义主对象这里
mainObjectName =" Company" ;;
mainObjectType = typeof(Class1);
//通用代码,相同在所有aspx页面上
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)
{
// ....
}
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)
{
//....
}
推荐答案
我只是好奇你在这里想要完成的事情......看起来很多
你讨论的项目会比继承更好地服务
copy /粘贴。
示例:
公共类MyPageBase:Page {
pro tected object mainObject; //用Object替换Class1来编辑
protected string mainObjectName;
protected Type mainObjectType;
// etc
}
然后
公共类MyChildPage:MyBasePage {
}
>
" Celine" < PL *** @ letsdothatagain.com>在消息中写道
新闻:11 ********************** @ j73g2000cwa.googlegr oups.com ...
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...
我有一组类似的类(c1,c2,...)。
我想创建一个模板(或一个尽可能多抽象的页面
)复制/粘贴,并创建ASPX页面来编辑
(添加/更新/ ...)这些类。
每个类的自定义页面,因为它们之间几乎没有差异
除了这个(复制的)模板,我还要定义我要编辑的类的名称。
以下生成错误,但你明白了:
公共类TemplateEdit:System.Web.UI.Page
{
protected Class1 mainObject; //用Object替换Class1来编辑
受保护的字符串mainObjectName;
protected类型mainObjectType;
//在此定义主对象
mainObjectName =" Company" ;;
mainObjectType = typeof(Class1);
//通用代码,所有aspx页面都相同
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)
{
// ....
}
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)
{
//....
}
很好,
这是解决方案的一部分,谢谢
但是仍然没有回答我的问题
假设我有一个session变量我想将这个主要对象转换为
特定的一个。
我需要在MyPageBase中写一个泛型类型
mainObject =(mainObjectTy PE)会话[mainObjectName]; //不用
工作
不能在自定义页面(AFAIK)中翻译成
Class1 mainObject = new( Class1);
mainObjectName =" Class1" ;;
mainObjectType = typeof(Class1);
此行将是副本/粘贴在所有页面而不是MyPageBase
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
我不明白你的问题的这一部分......你在问你怎么样? b $ b可以为您的页面添加通用吗?
干杯,
Greg Young
"席琳" < PL *** @ letsdothatagain.com>在消息中写道
news:11 ********************** @ v46g2000cwv.googlegr oups.com ...
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...
很好,
这是解决方案的一部分,谢谢
但是仍然没有回答我的问题
假设我有一个session变量我想将这个主要对象强制转换为特定的对象。
我需要在MyPageBase中编写泛型类型
mainObject =(mainObjectType)Session [mainObjectName]; //不工作
不能在自定义页面(AFAIK)中翻译成Class1 mainObject = new(Class1);
mainObjectName =" Class1" ;;
mainObjectType = typeof(Class1);
此行将在所有页面中复制/粘贴,而不是在MyPageBase中
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
这篇关于ASP.NET通用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!