Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to create a control or aspx page dynamically ?
Posted

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.
 
Share this answer
 
Thanks Murali for your quick response.

But found the solution in VirutalPathProvider as follows

C#
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;
        }
    }



This one has to be invoked in Application_Start as follows

C#
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
is automatically redirected to the VituralPath section and where we can process our Dynamic aspx and response the same

Thank you again...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900