本文整理汇总了C#中System.Web.UI.Page.FindControl方法的典型用法代码示例。如果您正苦于以下问题:C# Page.FindControl方法的具体用法?C# Page.FindControl怎么用?C# Page.FindControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.Page
的用法示例。
在下文中一共展示了Page.FindControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputerMove
private static void ComputerMove()
{
Random rand = new Random();
int positionIndex = rand.Next(0, freePositions.Count);
Position position = freePositions[positionIndex];
int row = position.X;
int col = position.Y;
if (game[row, col] == '*')
{
game[row, col] = computerCharacter;
freePositions.Remove(position);
Button btn = new Button();
Page page = new Page();
if (HttpContext.Current != null)
{
page = (Page)HttpContext.Current.Handler;
btn = (Button)page.FindControl("Btn" + row + col);
btn.Text = computerCharacter.ToString();
}
if (Win(computerCharacter))
{
Label lbWinner = (Label)page.FindControl("Winner");
lbWinner.Text = "You win!";
lbWinner.Visible = true;
computerScores++;
UpdateScores(page);
return;
}
}
else
{
ComputerMove();
}
}
示例2: RenderLabelTest
public static void RenderLabelTest (Page p)
{
Assert.AreEqual (Color.Black,((MyWebControl.Label) p.FindControl ("Label")).BackColor, "Default Theme#1");
Assert.AreEqual (Color.Red, ((MyWebControl.Label) p.FindControl ("LabelRed")).BackColor, "Red Skin Theme#2");
Assert.AreEqual (Color.Yellow, ((MyWebControl.Label) p.FindControl ("LabelYellow")).BackColor, "Yellow Skin Theme#3");
Assert.AreEqual (Color.Black, ((MyWebControl.Label) p.FindControl ("LabelOverride")).BackColor, "Override Skin Theme#4");
}
示例3: ChangeCss
/// <summary>
/// Find The HTML Element Inside The HTML Controls, Inside The User Control, Inside The Page And Change The Css Property Of It.
/// </summary>
/// <param name="page">Page</param>
/// <param name="userControlID">UserControlID</param>
/// <param name="htmlControlID">HTML ControlID</param>
/// <param name="elementID">Element ID</param>
/// <param name="key"> Css Tag</param>
/// <param name="value">Value</param>
public void ChangeCss(Page page, string userControlID, string htmlControlID, string elementID, string key, string value)
{
PlaceHolder pchWhole = page.FindControl(userControlID) as PlaceHolder;
UserControl uc = pchWhole.FindControl(htmlControlID) as UserControl;
HtmlGenericControl div = uc.FindControl(elementID) as HtmlGenericControl;
div.Attributes.Add(key, value);
}
示例4: FindPagesControlByID
public static Control FindPagesControlByID(string cid,Page page)
{
if (page.Master == null)
return page.FindControl(cid);
else
return page.Master.FindControl(cid);
}
示例5: RenderCSSPath
/// <summary>
/// Render CSS path.
/// </summary>
/// <param name="page">Page instance</param>
/// <param name="name">name</param>
/// <param name="cssFilePath">FilePath</param>
/// <param name="OverwriteExisting">Overwrite existing path if exists.</param>
public static void RenderCSSPath(Page page, string name, string cssFilePath, bool OverwriteExisting)
{
if (page == null || page.Header == null)
return;
if (cssFilePath == null)
cssFilePath = string.Empty;
HtmlLink link = (HtmlLink)page.FindControl(name);
//foreach (Control control in page.Header.Controls)
// if (control is HtmlLink)
// {
// HtmlLink link = (HtmlLink)control;
if (link != null)
{
if (link.ID.ToLower().Equals(name.ToLower()) && !string.IsNullOrEmpty(cssFilePath))
{
if (OverwriteExisting)
link.Href = cssFilePath;
else
{
if (String.IsNullOrEmpty(link.Href))
link.Href = cssFilePath;
}
// }
}
}
}
示例6: RegisterAjaxAntiForgery
public void RegisterAjaxAntiForgery(Page page)
{
var ctl = page.FindControl("ClientResourcesFormBottom");
if(ctl != null)
{
ctl.Controls.Add(new LiteralControl(AntiForgery.GetHtml().ToHtmlString()));
}
}
示例7: RegisterAjaxAntiForgery
public void RegisterAjaxAntiForgery(Page page)
{
var helper = CreateHtmlHelper();
var field = helper.AntiForgeryToken();
var ctl = page.FindControl("ClientResourcesFormBottom");
if(ctl != null)
{
ctl.Controls.Add(new LiteralControl(field.ToHtmlString()));
}
}
示例8: GetPostBackControl
public static Control GetPostBackControl(Page page)
{
string evTarget = page.Request.Params["__EVENTTARGET"];
if (!string.IsNullOrEmpty(evTarget))
{
return page.FindControl(evTarget);
}
else
{
foreach (string nCtrl in page.Request.Form)
{
Control ctrl = page.FindControl(nCtrl);
if (ctrl is Button)
{
return ctrl;
}
}
return null;
}
}
示例9: GetControlThatCausedPostBack
public static Control GetControlThatCausedPostBack(Page page)
{
//initialize a control and set it to null
Control ctrl = null;
//get the event target name and find the control
string ctrlName = page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(ctrlName))
ctrl = page.FindControl(ctrlName);
//return the control to the calling method
return ctrl;
}
示例10: SetPageTitle
public static void SetPageTitle(Page page, string sTitle)
{
try
{
Literal litPageTitle = page.FindControl("litPageTitle") as Literal;
if ( litPageTitle != null )
litPageTitle.Text = sTitle;
}
catch(Exception ex)
{
SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
}
}
示例11: GetPostBackControl
public static Control GetPostBackControl(Page page)
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button)
{
control = c;
break;
}
}
}
return control;
}
示例12: BindControl
public void BindControl(object t, Page page)
{
foreach (PropertyInfo pi in t.GetType().GetProperties())
{
if (pi.CanRead)
{
Control ctrl = page.FindControl(pi.Name);
if (ctrl != null)
{
object value = core.GetPropertyValue(t, pi);
SetControl(ctrl, value);
}
}
}
}
示例13: Prepare
/// <summary>
/// 准备控件。Ajax。
/// </summary>
/// <param name="page">WEB窗体引用。</param>
/// <param name="showLink">是否显示链接。null表示使用默认值。</param>
public static void Prepare(Page page, bool? showLink)
{
object ctl = null;
if (page.Master != null)
ctl = page.Master.FindControl("PWMessage");
if (ctl == null)
ctl = page.FindControl("PWMessage");
if (ctl != null)
{
((PopupWin)ctl).Visible = true;
if (showLink.HasValue)
{
((PopupWin)ctl).ShowLink = showLink.Value;
}
}
}
示例14: BindModel
public void BindModel(object t, Page page)
{
foreach (PropertyInfo pi in t.GetType().GetProperties())
{
if (pi.CanWrite)
{
Control ctrl = page.FindControl(pi.Name);
if (ctrl != null)
{
object ctrlVal = GetControl(ctrl);
try
{
core.SetPropertyValue(t, pi, ctrlVal);
}
catch (Exception)
{
}
}
}
}
}
示例15: EditPostbackFireEvent_Init
public static void EditPostbackFireEvent_Init (Page p)
{
FormView d = p.FindControl ("FormView1") as FormView;
if (d != null) {
d.ModeChanged +=new EventHandler(d_ModeChanged);
d.ModeChanging+=new FormViewModeEventHandler(d_ModeChanging);
d.ItemCommand += new FormViewCommandEventHandler (d_ItemCommand);
d.ItemUpdating += new FormViewUpdateEventHandler (d_ItemUpdating);
d.ItemUpdated += new FormViewUpdatedEventHandler (d_ItemUpdated);
}
}