本文整理汇总了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);
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
}
示例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();
}