动态添加 HTML 到 ASP.NET 页面
有人可以建议将 HTML 内容动态添加到 ASP.NET 页面的“正确”方法是什么吗?
我知道以下声明方法。
//Declaration
<%= MyMethodCall() %>
//And in the code behind.
protected String MyMethodCall()
{
return "Test Value";
}
有更好的或最佳实践方法吗?
编辑:我正在根据特定文件夹中的图像动态构建 Galleriffic 照片库。
Could someone please advise what the "correct" method is for adding HTML content to an ASP.NET page dynamically?
I am aware of the following declarative method.
//Declaration
<%= MyMethodCall() %>
//And in the code behind.
protected String MyMethodCall()
{
return "Test Value";
}
Is there a better or best practice way?
EDIT: I am building a Galleriffic photo gallery dynamically depending on the images located in a specific folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
取决于你想做什么。
对于控件/文本,我通常使用
LiteralControl
并将Text
属性设置为我要添加的 HTML,然后可以将此控件添加到您想要的页面上的任何位置出现LiteralControl 参考是
这里
可以看到你想要的 Galleriffic ,我想它会像这样伪出现......
Depends what you want to do.
For controls/text I normally use a
LiteralControl
and set theText
property as the HTML I want to add, then this control can be added anywhere on the page that you want it to appearLiteralControl reference is
here
ok seeing as you want it for Galleriffic, I guess it would pseudo-appear as such...
Aspx:
背后代码:
Aspx :
Code behind :
有多种方法可以做到这一点,使用哪种方法实际上取决于您的场景和偏好。
There are several ways to do that, which to use really depends on your scenario and preference.
另一种选择
Another option