终于是找到原来在webform里面已经提供了htmlcontrol这样的控件,可以直接拿来用。以前一直在想mvc有htmlhelper,webform里面不能用,其实是webform里面已经有了。

例子

HtmlGenericControl htmlgeneric = new HtmlGenericControl("div");
htmlgeneric.Attributes.Add("data-dojo-type", "dijit/Toolbar");
htmlgeneric.ClientIDMode = ClientIDMode.Static;//.net 4下面才有此属性,2的话就没有了。
htmlgeneric.ID = "toolbar1";

HtmlGenericControl btna = new HtmlGenericControl("div");
btna.Attributes.Add("data-dojo-type", "dijit/form/Button");
btna.Attributes.Add("data-dojo-props", "iconClass:'dijitIconDelete', showLabel:false,onClick:function(){ return Delete();}");
btna.ClientIDMode = ClientIDMode.Static;
btna.ID = "toolbar1.clear";

HtmlGenericControl griddiv = new HtmlGenericControl("div");
griddiv.ClientIDMode = ClientIDMode.Static;
griddiv.ID = "gridDiv";

htmlgeneric.Controls.Add(btna);

this.Controls.Add(htmlgeneric);
this.Controls.Add(griddiv);

05-11 13:50