如何在运行时添加控件 [英] how to add control in runtime

查看:140
本文介绍了如何在运行时添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态创建控件或aspx页面?

How to create a control or aspx page dynamically ?

推荐答案



据我所知,我们可以将用户控件或Web控件动态地插入到Webforms中.

这里''提供了一些有关如何将控件动态绑定到页面的链接.

http://msdn.microsoft.com/en-us/library/kyt0fzt1.aspx

以下链接用于动态创建网页.

http://www.daniweb.com/web-development/aspnet/threads/5751


希望这些链接对您有用.

一切顺利.
Hi,

Upto my knowledge we can insert usercontrols or webcontrols dynamically into webforms .

Here ''m providing some link to how to bind control into page dynamically.

http://msdn.microsoft.com/en-us/library/kyt0fzt1.aspx

And the below link used for creating web page in dynamically.

http://www.daniweb.com/web-development/aspnet/threads/5751


I hope these links are usefull to you.

All the best.


感谢Murali的快速响应.

但如下在VirutalPathProvider中找到了解决方案

Thanks Murali for your quick response.

But found the solution in VirutalPathProvider as follows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.IO;


    public class CHttpHandler : System.Web.Hosting.VirtualPathProvider
    {
        public CHttpHandler() { }
        private bool IsAppResourcePath(string virtualPath)
        {
            String checkPath =
               VirtualPathUtility.ToAppRelative(virtualPath);
            return checkPath.StartsWith("~/App_Resource/", StringComparison.InvariantCultureIgnoreCase);
        }
        public override bool FileExists(string virtualPath)
        {
            return (IsAppResourcePath(virtualPath) || base.FileExists(virtualPath));
        }
        public override VirtualFile GetFile(string virtualPath)
        {
            if (IsAppResourcePath(virtualPath))
                return new AssemblyResourceVirtualFile(virtualPath);
            else
                return base.GetFile(virtualPath);
        }
        public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
        {
            if (IsAppResourcePath(virtualPath))
                return null;
            else
                return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
        }
    }

    class AssemblyResourceVirtualFile : VirtualFile
    {
        string path;
        public AssemblyResourceVirtualFile(string virtualPath)
            : base(virtualPath)
        {
            path = VirtualPathUtility.ToAppRelative(virtualPath);
        }
        public override System.IO.Stream Open()
        {
            try
            {
               //return Stream with the ASPX Content eg. <asp:button runat="server" xmlns:asp="#unknown" />
            }
            catch (Exception Ex)
            {
            }
            return null;
        }
    }




必须在Application_Start中按如下方式调用该程序




This one has to be invoked in Application_Start as follows

void Application_Start(object sender, EventArgs e)
{
  // Code that runs on application startup
  System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new CHttpHandler());
}



一旦实现,当用户请求



Once implemented when the user request any page under

/App_Resource/custom.aspx

下的任何页面时,该页面将自动重定向到VituralPath部分,在此处我们可以处理动态aspx并响应相同的内容

再次感谢您...

is automatically redirected to the VituralPath section and where we can process our Dynamic aspx and response the same

Thank you again...




检查这些-

使用c#
http://geekswithblogs.net/dotNETvinz/存档/2009/03/17/dynamically-adding-textbox-control-to-aspnet-table.aspx [ http://forums.asp.net/p/1694920/4483014.aspx/1?Re + Help + with + this + jquery + code + [ http://forums.asp.net/p/1655464/4311583. aspx/1?Re + Create + Textbox + OnRunTime [ ^ ]
Hi,

Check these-

Using c#
http://geekswithblogs.net/dotNETvinz/archive/2009/03/17/dynamically-adding-textbox-control-to-aspnet-table.aspx[^]

Using jQuery-
http://forums.asp.net/p/1694920/4483014.aspx/1?Re+Help+with+this+jquery+code+[^]
http://forums.asp.net/p/1655464/4311583.aspx/1?Re+Create+Textbox+OnRunTime[^]


这篇关于如何在运行时添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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