当前位置: 首页>>代码示例>>C#>>正文


C# Page.LoadControl方法代码示例

本文整理汇总了C#中Page.LoadControl方法的典型用法代码示例。如果您正苦于以下问题:C# Page.LoadControl方法的具体用法?C# Page.LoadControl怎么用?C# Page.LoadControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Page的用法示例。


在下文中一共展示了Page.LoadControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: initPage

    /// <summary>
    /// 初始化页面
    /// </summary>
    /// <param name="thepage">当前页面对象</param>
    /// <param name="index">页面菜单索引</param>
    /// <param name="title">页面标题</param>
    /// <param name="plhdTitle">标题控件</param>
    /// <param name="plhdHeader">头部控件</param>
    /// <param name="plhdSlide">侧栏控件</param>
    /// <param name="plhdFooter">底部控件</param>
    public static void initPage(Page thepage, int index, string title, PlaceHolder plhdTitle, PlaceHolder plhdHeader, PlaceHolder plhdSlide, PlaceHolder plhdFooter)
    {
        string titleID = "u_title";
        string headerID = "u_header";
        string sliderID = "u_slider";
        string footerID = "u_footer";

        //get menu name
        string menuName = "menu" + index;
        string subMenuName = "subMenu" + index;

        //get title
        Control ctitle = thepage.LoadControl("pageControl/title.ascx");
        ctitle.ID = titleID;
        (ctitle.FindControl("ltrTitle") as Literal).Text = title;
        plhdTitle.Controls.Add(ctitle);

        //get header
        Control cheader = thepage.LoadControl("pageControl/header.ascx");
        cheader.ID = headerID;
        (cheader.FindControl(menuName) as Literal).Text = " class=\"current\"";//高亮父菜单
        cheader.FindControl(subMenuName).Visible = true;//高亮子菜单
        plhdHeader.Controls.Add(cheader);

        //get slider
        Control cslider = thepage.LoadControl("pageControl/slidePanel.ascx");
        cslider.ID = sliderID;
        plhdSlide.Controls.Add(cslider);

        //get footer
        Control cfooter = thepage.LoadControl("pageControl/footer.ascx");
        cfooter.ID = footerID;
        plhdFooter.Controls.Add(cfooter);
    }
开发者ID:TheProjecter,项目名称:wgiadunion,代码行数:44,代码来源:uLoadControl.cs

示例2: GetControlHtml

    public string GetControlHtml(string controlLocation,string username, string userid)
    {
        // Create instance of the page control
        Page page = new Page();

        // Create instance of the user control
        UserControl userControl = (UserControl)page.LoadControl(controlLocation);

        //Disabled ViewState- If required
        //userControl.EnableViewState = false;

        //Form control is mandatory on page control to process User Controls
        HtmlForm form = new HtmlForm();

        //Add user control to the form
        form.Controls.Add(userControl);

        //Add form to the page
        page.Controls.Add(form);

        //Write the control Html to text writer
        StringWriter textWriter = new StringWriter();

        //execute page on server
        HttpContext.Current.Server.Execute(page, textWriter, false);

        // Clean up code and return html
           // string html = Regex.Replace(textWriter.ToString(), "(.*(\r|\n|\r\n))*.*<div id=.{1}wrapperAjax.{1} />", "", RegexOptions.IgnoreCase);

        string html = textWriter.ToString().Replace("userName", username).Replace("userid", userid).Replace("(.*(\r|\n|\r\n))*.*<div id=.{1}wrapperAjax.{1} />","");

        return html;
    }
开发者ID:rzukowski,项目名称:Sport,代码行数:33,代码来源:DownloadUploadForm.cs

示例3: RenderView

    public static string RenderView(string path, object data)
    {
        Page pageHolder = new Page();
        UserControl viewControl = (UserControl)pageHolder.LoadControl(path);

        if (data != null)
        {
            Type viewControlType = viewControl.GetType();
            FieldInfo field = viewControlType.GetField("Data");

            if (field != null)
            {
                field.SetValue(viewControl, data);
            }
            else
            {
                throw new Exception("View file: " + path + " does not have a public Data property");
            }
        }

        pageHolder.Controls.Add(viewControl);

        StringWriter output = new StringWriter();
        HttpContext.Current.Server.Execute(pageHolder, output, false);

        return output.ToString();
    }
开发者ID:publichealthcloud,项目名称:absenteesurveillance,代码行数:27,代码来源:ToolTipWebService.cs

示例4: LoadControl

 public string LoadControl(string name)
 {
     Page Page = new Page();
     var Control = Page.LoadControl("~/Controls/" + name + ".ascx");
     Page.Controls.Add(Control);
     StringWriter StringWriter = new StringWriter();
     HttpContext.Current.Server.Execute(Page, StringWriter, true);
     return StringWriter.ToString();
 }
开发者ID:johncoffee,项目名称:eventblock,代码行数:9,代码来源:ApiController.cs

示例5: LoadControl

 public string LoadControl(string path, HttpContext context)
 { 
     Page pg = new Page();
     StringWriter sw = new StringWriter();
     UserControl uc = pg.LoadControl(path) as UserControl;
     pg.Controls.Add(uc);
     context.Server.Execute(pg, sw, true);
     return sw.ToString();
 }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:9,代码来源:ChatList.cs

示例6: RenderView

 public static string RenderView(string path)
 {
     Page pageHolder = new Page();
     UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
     pageHolder.Controls.Add(viewControl);
     StringWriter output = new StringWriter();
     HttpContext.Current.Server.Execute(pageHolder, output, true);
     return output.ToString();
 }
开发者ID:johncoffee,项目名称:eventblock,代码行数:9,代码来源:SiteLogic.cs

示例7: GetFlagReader

    public string GetFlagReader()
    {
        Page page = new Page();
        UserControl ctl =
          (UserControl)page.LoadControl("UserControls/CountryFlag.ascx");

        page.Controls.Add(ctl);

        StringWriter writer = new StringWriter();
        HttpContext.Current.Server.Execute(page, writer, false);

        return writer.ToString();
    }
开发者ID:deepcaving,项目名称:hdb,代码行数:13,代码来源:CountryFlagReaderCS.cs

示例8: Results

    public static string Results(string controlName)
    {
        try
        {
            Page page = new Page();
            SageUserControl userControl = (SageUserControl)page.LoadControl(controlName);
            page.Controls.Add(userControl);

            StringWriter textWriter = new StringWriter();
            HttpContext.Current.Server.Execute(page, textWriter, false);
            return textWriter.ToString();
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
开发者ID:electrono,项目名称:veg-web,代码行数:17,代码来源:LoadControlHandler.aspx.cs

示例9: LoadControl

    private string LoadControl(string path, HttpContext context)
    {
        var temp = HttpRuntime.Cache[path];
        if (temp != null)
        {
            return ""+temp.ToString();
        }
        else
        {
            _page = new Page();
            StringWriter sw = new StringWriter();

            UserControl uc = _page.LoadControl(path) as UserControl;

            _page.Controls.Add(uc);
            context.Server.Execute(_page, sw, true);

            string PageHTML = sw.ToString();
            HttpRuntime.Cache.Insert(path, PageHTML, null, DateTime.Now.AddMilliseconds(500), TimeSpan.Zero);
            return PageHTML;
        }
    }
开发者ID:LittlePeng,项目名称:ncuhome,代码行数:22,代码来源:UserListHandler.cs

示例10: Results

    public static string Results(string controlName)
    {
        try
        {
            SageFrameConfig sfConf = new SageFrameConfig();
            string portalCulture = sfConf.GetSettingValueByIndividualKey(SageFrameSettingKeys.PortalDefaultLanguage);
            if (HttpContext.Current.Session[SessionKeys.SageUICulture] != null)
            {
                Thread.CurrentThread.CurrentUICulture = (CultureInfo)HttpContext.Current.Session[SessionKeys.SageUICulture];
            }
            else
            {
                CultureInfo newUICultureInfo = new CultureInfo(portalCulture);
                Thread.CurrentThread.CurrentUICulture = newUICultureInfo;
                HttpContext.Current.Session[SessionKeys.SageUICulture] = newUICultureInfo;
            }
            if (HttpContext.Current.Session[SessionKeys.SageUICulture] != null)
            {
                Thread.CurrentThread.CurrentCulture = (CultureInfo)HttpContext.Current.Session[SessionKeys.SageUICulture];
            }
            else
            {
                CultureInfo newCultureInfo = new CultureInfo(portalCulture);
                Thread.CurrentThread.CurrentCulture = newCultureInfo;
                HttpContext.Current.Session[SessionKeys.SageUICulture] = newCultureInfo;
            }
            Page page = new Page();
            SageUserControl userControl = (SageUserControl)page.LoadControl(controlName);
            page.Controls.Add(userControl);

            StringWriter textWriter = new StringWriter();
            HttpContext.Current.Server.Execute(page, textWriter, false);
            return textWriter.ToString();
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
开发者ID:xiaoxiaocoder,项目名称:AspxCommerce2.7,代码行数:39,代码来源:LoadControlHandler.aspx.cs

示例11: GetPostPublicUrl

	private static string GetPostPublicUrl(BXBlogPost post, Page page)
	{
		if (!BXModuleManager.IsModuleInstalled("search"))
			return string.Empty;

		string url;
		if(postUrls.TryGetValue(post.Id, out url))
			return url;

		BXControl label = (BXControl)page.LoadControl("~/bitrix/admin/controls/Blog/BlogPostLabel.ascx");
		label.Attributes["PostID"] = post.Id.ToString();
		label.Attributes["PostTitle"] = post.TextEncoder.Decode(post.Title);
        
		StringBuilder sb = new StringBuilder();
		using(StringWriter sw = new StringWriter(sb))
			using(HtmlTextWriter w = new HtmlTextWriter(sw))
				label.RenderControl(w);
		url = sb.ToString();
		postUrls[post.Id] = url;

		return url;
	}
开发者ID:mrscylla,项目名称:volotour.ru,代码行数:22,代码来源:BlogCommentList.aspx.cs

示例12: GetForums

        public string GetForums(string categoryId)
        {
            Page page = new Page();

            CategoryForums ctl = (CategoryForums)page.LoadControl("~/UserControls/CategoryForums.ascx");

            ctl.Member = Members.GetMember(HttpContext.Current.User.Identity.Name);
            ctl.CategoryId = categoryId;
            page.Controls.Add(ctl);
            HtmlForm tempForm = new HtmlForm();
            tempForm.Controls.Add(ctl);
            page.Controls.Add(tempForm);
            StringWriter writer = new StringWriter();
            HttpContext.Current.Server.Execute(page, writer, false);
            string outputToReturn = writer.ToString();
            outputToReturn = outputToReturn.Substring(outputToReturn.IndexOf("<div"));
            outputToReturn = outputToReturn.Substring(0, outputToReturn.IndexOf("</form>"));
            writer.Close();
            string viewStateRemovedOutput = Regex.Replace(outputToReturn,
            "<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\".*?\" />",
            "", RegexOptions.IgnoreCase);
            return viewStateRemovedOutput;
        }
开发者ID:huwred,项目名称:SnitzDotNet,代码行数:23,代码来源:CommonFunc.asmx.cs

示例13: LoadUserControl

    /// <summary>
    /// Load a UserControl and pass params to it
    /// </summary>
    /// <param name="page">Page</param>
    /// <param name="userControlPath">Path of the user control</param>
    /// <param name="constructorParameters">Contructor parameters of your user control, seperate them by comma (,)</param>
    /// <returns>Your UserControl</returns>
    public static UserControl LoadUserControl(Page page, string userControlPath, params object[] constructorParameters)
    {
        List<Type> constParamTypes = new List<Type>();
        foreach (object constParam in constructorParameters)
        {
            constParamTypes.Add(constParam.GetType());
        }
        UserControl ctl = page.LoadControl(userControlPath) as UserControl;

        // Find the relevant constructor
        ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());

        //And then call the relevant constructor
        if (constructor == null)
        {
            throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
        }
        else
        {
            constructor.Invoke(ctl, constructorParameters);
        }

        // Finally return the fully initialized UC
        return ctl;
    }
开发者ID:lengocluyen,项目名称:pescode,代码行数:32,代码来源:CoreSupport.cs

示例14: AddControls

        public void AddControls(
            string strXML,
            PlaceHolder plaPlaceHolder,
            Page pagMain,
            bool bolShowNonFixed)
        {
            System.Xml.XmlDocument docXML;
            System.Xml.XmlNodeList lstSections;
            int intCounter;
            string strSectionType;
            string strIsFixed;
            bool bolIsFixed;
            ISectionControl secSection;
            Control ctrTemp;

            docXML = new System.Xml.XmlDocument();

            docXML.LoadXml(strXML);

            lstSections = docXML.DocumentElement.SelectNodes("/package/section");

            //System.Diagnostics.Debug.WriteLine("lstSections.Count: " + lstSections.Count.ToString());

            for (intCounter = 0;
                intCounter < lstSections.Count;
                intCounter++)
            {
                //System.Diagnostics.Debug.WriteLine("Section Type: " + lstSections[intCounter].Attributes["type"]);

                if (lstSections[intCounter].Attributes["type"] != null)
                {
                    strSectionType = lstSections[intCounter].Attributes["type"].Value;

                    bolIsFixed = true;

                    if (lstSections[intCounter].Attributes["isfixed"] != null)
                    {
                        strIsFixed = lstSections[intCounter].Attributes["isfixed"].Value;

                        if (strIsFixed.ToLower() == "false")
                            bolIsFixed = false;
                    }

                    //System.Diagnostics.Debug.WriteLine(strSectionType);

                    switch (strSectionType)
                    {
                        case "html":
                            if ((!bolShowNonFixed) && (!bolIsFixed))
                            {
                                continue;
                            }

                            //System.Diagnostics.Trace.WriteLine(lstSections[intCounter].ToString());

                            ctrTemp = pagMain.LoadControl(SECTION_HTML);

                            secSection = (ISectionControl)ctrTemp;

                            secSection.SetSection(lstSections[intCounter]);

                            plaPlaceHolder.Controls.Add(ctrTemp);

                            break;
                        case "auction":

                            OnAuctionTypeReached(plaPlaceHolder);

                            break;
                        default:
                            break;
                    }
                }
            }
        }
开发者ID:0huah0,项目名称:csharp-samples,代码行数:75,代码来源:XMLCoverter.cs

示例15: LoadOrderSummary

 public string LoadOrderSummary()
 {
     Page Page = new Page();
     var Control = Page.LoadControl("~/Controls/BasketPanel.ascx");
     Page.Controls.Add(Control);
     StringWriter StringWriter = new StringWriter();
     HttpContext.Current.Server.Execute(Page, StringWriter, true);
     return StringWriter.ToString();
 }
开发者ID:johncoffee,项目名称:eventblock,代码行数:9,代码来源:OrdersLogic.cs


注:本文中的Page.LoadControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。