Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从字符串加载.ascx(SQL)_C#_Asp.net_Controls - Fatal编程技术网

C# 从字符串加载.ascx(SQL)

C# 从字符串加载.ascx(SQL),c#,asp.net,controls,C#,Asp.net,Controls,我想问,有没有办法从字符串加载ascx控件?更准确地说:我喜欢在sql中创建/存储一个新的.ascx,然后将其加载到网站。是的,您应该能够使用ParseControl函数执行您想要的操作: MSDN中的示例: <%@ Page language="c#" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/D

我想问,有没有办法从字符串加载ascx控件?更准确地说:我喜欢在sql中创建/存储一个新的.ascx,然后将其加载到网站。

是的,您应该能够使用ParseControl函数执行您想要的操作:

MSDN中的示例:

<%@ Page language="c#" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ASP.NET Example</title>
<script runat="server">
    // System.Web.UI.TemplateControl.ParserControl;
    // The following example demonstrates the method 'ParseControl' of class TemplateControl.
    // Since TemplateControl is abstract, this sample has been written using 'Page' class which derives from 
    // 'TemplateControl' class.
    // A button object is created by passing a string to contstruct a button using ASP syntax, to the 
    // 'ParseControl' method. This button is added as one of the child controls of the page and displayed.
    void Page_Load(object sender, System.EventArgs e)
    {
      Control c = ParseControl("<asp:button text='Click here!' runat='server' />");
      myPlaceholder.Controls.Add(c);
    }
    </script>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:placeholder id ="myPlaceholder" runat="server" />
    </form>
  </body>
</html>