插入许多asp.net控件 [英] Inserting many asp.net controls
问题描述
我必须在asp.net web-part文件中放入许多asp.net控件。我想制作一些高级结构,例如< controlblock id =" a" />转换为< div class =" abe">< input type =" text" id =" a" />< / div>。
这是示例。
实际上这样做也可以让我在高级别编程并轻松管理更改,因为我的表单会有一个模式后面的100个元素。
我可以使用代码段但不符合我的要求。
只有选项似乎可行才是自己编写编译器将我的代码转换为我需要的html。我也在考虑使用XML作为源和XSLT来获取我想要的HTML。
Shahid Roofi
您好,
据我所知,Asp.Net LiteralControl可以让你根据需要渲染html控件。 / span>
protected override void CreateChildControls(){
this.Controls.Add(new LiteralControl("< h3> Value:")) );
TextBox box = new TextBox();
box.Text =" 0" ;;
this.Controls.Add(box);
this.Controls.Add(new LiteralControl("< / h3>"));
}
你可以创建一个' Factory'根据您的逻辑创建控件,这样您就不需要逐个创建。
您可以查看以下链接,了解有关LiteralControl的更多详细信息。
https:/ /msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol(v=vs.110).aspx
< p style ="vertical-align:middle"> 如果LiteralControl不符合您的要求,您可以创建自定义控件。
以下是供您参考的主题。
https://msdn.microsoft.com/en -us / library / yhzc935f(v = vs.100).aspx
最好的问候,
利跨度>
I have to drop in many asp.net controls on a asp.net web-part file. I want to make some some high level constructs like <controlblock id="a"/> which transforms into <div class="abe"><input type="text" id="a"/></div>.
This is example.
Actually doing so will also me to program at high level and manage changes easily because my form will have 100's of elements following a pattern.
I can use snippets but that does not map to my requirements.
Only option seems viable is to write a compiler myself to convert my code into html that i need. i am also thinking of using XML as source and XSLT to get HTML i want.
Shahid Roofi
Hi,
As per my knowledge, Asp.Net LiteralControl enable you render the html control as you want.
protected override void CreateChildControls() { this.Controls.Add(new LiteralControl("<h3>Value: ")); TextBox box = new TextBox(); box.Text = "0"; this.Controls.Add(box); this.Controls.Add(new LiteralControl("</h3>")); }
You may create a ‘Factory’ to create the controls based on your logic so you don’t need to create one by one.
You could check below link for more details about LiteralControl.
https://msdn.microsoft.com/en-us/library/system.web.ui.literalcontrol(v=vs.110).aspx
If LiteralControl doesn’t meet your requirement, you could create your custom controls.
Here is the thread for your reference.
https://msdn.microsoft.com/en-us/library/yhzc935f(v=vs.100).aspx
Best Regards,
Lee
这篇关于插入许多asp.net控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!