从Blob存储在asp.net中加载Web用户控件 [英] Loading web user controls from blob storage in asp.net

查看:301
本文介绍了从Blob存储在asp.net中加载Web用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储其他位置的用户控件文件可能在Blob存储或其他一些地方。 (不是在我的项目工作空间),我存储在数据库中的用户控件的URL。现在,这个用户控件如何可以加载到我的网页?

I am storing user control file in some other location may be in blob storage or some other place. ( not in my project work space ) and i store the url of the user control in database . Now how can load this usercontrol to my web page ?

推荐答案

我已经用下面的方法来加载的.ascx控件。事实上,我已经保存.ascx文件为文本字段。

I'd used following approach to load .ascx controls. In fact I've saved .ascx files into "text" field.

首先我已经注册在web.config文件控制:

First of I've register a control in web.config file:

<pages>
  <controls>
    <add  tagPrefix="tab" src="~/pg.ascx" tagName="Test"/>
  </controls>
</pages>

在网络表格,我从数据库中读取的.ascx内容并保存它动态地根和用户负荷控制下pg.ascx。

In webform, I read .ascx content from the database and save it to pg.ascx under the root and load user control dynamically.

Control t = LoadControl("~/pg.ascx");
PlaceHolder1.Controls.Add(t);

编辑:
我加入,我已经存入StringBuilder对象的用户控件定义。

I'm adding a user control definition which I've stored into StringBuilder object.

System.Text.StringBuilder sb = new System.Text.StringBuilder();
 sb.Append("<%@ Control Language=\"C#\" ClassName=\"m1\" %>");
 sb.Append("<script runat=\"server\">");
 sb.Append("int no=10;");
 sb.Append("public void page_load(){ for(int i=1;i<=no;i++) { Response.Write(i);} }");
 sb.Append("</script>");
 sb.Append("<h1>Hello</h1>");

 System.IO.File.WriteAllText(MapPath("~/pg.ascx"), sb.ToString());
 Control t = LoadControl("~/pg.ascx");
 PlaceHolder1.Controls.Add(t);

这篇关于从Blob存储在asp.net中加载Web用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆