本文整理汇总了C#中System.Web.UI.WebControls.PlaceHolder.FindControl方法的典型用法代码示例。如果您正苦于以下问题:C# PlaceHolder.FindControl方法的具体用法?C# PlaceHolder.FindControl怎么用?C# PlaceHolder.FindControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.WebControls.PlaceHolder
的用法示例。
在下文中一共展示了PlaceHolder.FindControl方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadRecipeImage
public static void UploadRecipeImage(LyricRepository Lyric, PlaceHolder ph, string directory, int maxsize, bool IsEdit)
{
FileUpload ImageUpload = (FileUpload)(ph.FindControl("RecipeImageFileUpload"));
if (ImageUpload.HasFile) //Check if there is a file
{
//Constant variables
string Directory = directory;
int maxFileSize = maxsize;
int FileSize = ImageUpload.PostedFile.ContentLength; //Get th file lenght
string contentType = ImageUpload.PostedFile.ContentType; // Get the file type
string FileExist = Directory + ImageUpload.PostedFile.FileName; // Get the filename from the directory and compare
string FileName = Path.GetFileNameWithoutExtension(ImageUpload.PostedFile.FileName); //Get the posted filename
string FileExtention = Path.GetExtension(ImageUpload.PostedFile.FileName); //Get the posted file extension
string FilePath;
string FileNameWithExtension;
//File type validation
if (!contentType.Equals("image/gif") &&
!contentType.Equals("image/jpeg") &&
!contentType.Equals("image/jpg") &&
!contentType.Equals("image/png"))
{
return;
}
// File size validation
else if (FileSize > maxFileSize)
{
return;
}
else
{
//Check wether the image name already exist.
//If the image name already exist, append a random
//numeric and letter to ensure the image name is always unqiue.
if (File.Exists(HttpContext.Current.Server.MapPath(FileExist)))
{
//Create a random alpha numeric to make sure the updated image name is unique.
Random rand = new Random((int)DateTime.Now.Ticks);
int randnum = rand.Next(1, 10);
int CharCode = rand.Next(Convert.ToInt32('a'), Convert.ToInt32('z'));
char RandomChar = Convert.ToChar(CharCode);
//Get directory, the file name and the extension.
FilePath = string.Concat(Directory, FileName + randnum + RandomChar, "", FileExtention);
//Joined the filename and extension to insert into the database.
FileNameWithExtension = FileName + randnum + RandomChar + FileExtention;
//Initialize Add recipe object property to get the full image name
Lyric.LyricImage = FileNameWithExtension;
try
{
//Save the recipe image to the specified directory
//Make sure the "LyricImage" folder has write permission to upload image
ImageUpload.SaveAs(HttpContext.Current.Server.MapPath(FilePath));
}
catch
{
}
}
else
{
//Get directory, the file name and the extension.
FilePath = string.Concat(Directory, FileName, "", FileExtention);
//Joined the filename and extension to insert into the database.
FileNameWithExtension = FileName + FileExtention;
//Initialize Add recipe object property to get the full image name
Lyric.LyricImage = FileNameWithExtension;
try
{
//Save the recipe image to the specified directory
//Make sure the "LyricImage" folder has write permission to upload image
ImageUpload.SaveAs(HttpContext.Current.Server.MapPath(FilePath));
}
catch
{
}
}
}
}
else
{
if (!IsEdit)
{
//If there is no image to be uploaded, then assign an empty string to the property
Lyric.LyricImage = string.Empty;
}
else
{
//This section is executed if the input file is empty.
//.........这里部分代码省略.........
示例2: GetIdentifyItemNewPopular
/// <summary>
/// Return whether an item is new or popular and display its associated image or text in recipedetail page.
/// </summary>
public static void GetIdentifyItemNewPopular(DateTime strDate, PlaceHolder ph, int Popular)
{
//Find controls
Label PopularLabel = (Label)(ph.FindControl("lblpopular"));
Image thumbsupimg = (Image)(ph.FindControl("thumbsup"));
Image Newimage = (Image)(ph.FindControl("newimg"));
//Get thumbs up image - indicate that the item is hot or popular.
ShowPopularImage(Popular, PopularLabel, thumbsupimg);
//Get new image if item is less than or equal to 7 days old
ShowNewImage(DateTime.Now.Subtract(strDate), Newimage);
}
示例3: UploadUserImage
public static void UploadUserImage(UserRepository User, PlaceHolder ph, string directory, int maxsize)
{
FileUpload ImageUpload = (FileUpload)(ph.FindControl("UserImageFileUpload"));
if (ImageUpload.HasFile) //Check if there is a file
{
//Constant variables
string Directory = directory;
int maxFileSize = maxsize;
int FileSize = ImageUpload.PostedFile.ContentLength; //Get th file lenght
string contentType = ImageUpload.PostedFile.ContentType; // Get the file type
string FileExist = Directory + ImageUpload.PostedFile.FileName; // Get the filename from the directory and compare
string FileName = User.Username; //Use username as the image name. Username is unique so no problem with this.
string FileExtention = Path.GetExtension(ImageUpload.PostedFile.FileName); //Get the posted file extension
string FilePath;
string FileNameWithExtension;
//File type validation
if (!contentType.Equals("image/gif") &&
!contentType.Equals("image/jpeg") &&
!contentType.Equals("image/jpg") &&
!contentType.Equals("image/png"))
{
return;
}
// File size validation
else if (FileSize > maxFileSize)
{
return;
}
else
{
//If the user updated the photo, just overwrite the old one.
//Get directory, the file name and the extension.
FilePath = string.Concat(Directory, FileName, "", FileExtention);
//Joined the filename and extension to insert into the database.
FileNameWithExtension = FileName + FileExtention;
//Initialize Add recipe object property to get the full image name
User.Photo = FileNameWithExtension;
try
{
//Save the recipe image to the specified directory
//Make sure the "LyricImage" folder has write permission to upload image
ImageUpload.SaveAs(HttpContext.Current.Server.MapPath(FilePath));
}
catch
{
}
}
}
else
{
//If there is no image to be uploaded, then assign an empty string to the property
User.Photo = string.Empty;
}
}
示例4: IncludeStartupEvents
/// <summary>
/// Registers startup events
/// </summary>
/// <param name="EventLocation"> Event locations</param>
/// <param name="PortalID">portalID</param>
/// <param name="phdContainer">Placeholder name</param>
/// <param name="IsAdmin">Set true for admin part</param>
public void IncludeStartupEvents(SystemEventLocation EventLocation, int PortalID, PlaceHolder phdContainer, bool IsAdmin)
{
SystemStartupController obj = new SystemStartupController();
ArrayList arrColl = new ArrayList();
switch (EventLocation)
{
case SystemEventLocation.Top:
arrColl = obj.GetStartUpControls("Top", PortalID, IsAdmin);
for (int i = 0; i < arrColl.Count; i++)
{
try
{
UserControl ctl = this.Page.LoadControl("~/" + arrColl[i].ToString()) as SageFrameStartUpControl;
if (ctl != null)
{
this.Page.Controls.AddAt(0, ctl);
}
}
catch
{
}
}
break;
case SystemEventLocation.Middle:
arrColl = obj.GetStartUpControls("Middle", PortalID, IsAdmin);
UserControl uc = phdContainer.FindControl("lytA") as UserControl;
for (int i = 0; i < arrColl.Count; i++)
{
try
{
UserControl ctl = this.Page.LoadControl("~/" + arrColl[i].ToString()) as SageFrameStartUpControl;
PlaceHolder phdPlaceHolderMiddle = uc.FindControl("pch_middlemaincurrent") as PlaceHolder;
if (phdPlaceHolderMiddle != null && ctl != null)
{
phdPlaceHolderMiddle.Controls.Add(ctl);
}
}
catch
{
}
}
break;
case SystemEventLocation.Bottom:
arrColl = obj.GetStartUpControls("Bottom", PortalID, IsAdmin);
for (int i = 0; i < arrColl.Count; i++)
{
try
{
UserControl ctl = this.Page.LoadControl("~/" + arrColl[i].ToString()) as SageFrameStartUpControl;
if (ctl != null)
{
this.Page.Controls.AddAt(this.Page.Controls.Count, ctl);
}
}
catch
{
}
}
break;
}
}
示例5: displayLogin
protected void displayLogin(PlaceHolder placeholder)
{
LoginHelper.drawByAuthenticated(placeholder);
Button bt = ((Button)placeholder.FindControl("loginButton"));
bt.Click += new System.EventHandler(loginDo);
}
示例6: CreateChildControls
//.........这里部分代码省略.........
// 检索按钮
this.Controls.Add(new LiteralControl(
"<tr class='cmdline'><td></td><td colspan='" + Convert.ToString(nCols - 1) + "'>"
));
// Search Button
Button button = new Button();
button.ID = "search_button";
button.Text = this.GetString("检索");
button.CssClass = "search";
button.Click += new EventHandler(this.SearchButton_Click);
this.Controls.Add(button);
// 增加前端事件代码,以便响应回车按钮
for (int i = 0; i < textboxs.Count; i++)
{
TextBox box = textboxs[i];
box.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + button.ClientID + "').click();return cancelClick();}} else {return true}; "); // 原来为 button.UniqueID 也可用
}
this.Controls.Add(new LiteralControl(
"</td></tr>"
));
// 调试信息行
PlaceHolder resultline = new PlaceHolder();
resultline.ID = "resultline";
this.Controls.Add(resultline);
CreateResultLine(resultline);
{
PlaceHolder line = (PlaceHolder)FindControl("resultline");
TableCell cell = (TableCell)line.FindControl("resultinfo");
button.Attributes.Add("onclick", "document.getElementById('" + cell.ClientID + "').innerText = '"
+ this.GetString("正在检索...")
+ "';return true;");
}
// 面板风格选择列表
literal = new LiteralControl("<tr class='panelstyle'><td colspan='" + Convert.ToString(nCols) + "'>"
+ this.GetString("检索面板风格")
+ " ");
this.Controls.Add(literal);
if ((this.SearchPanelStyle & SearchPanelStyle.PanelStyleSwitch) == SearchPanelStyle.PanelStyleSwitch)
literal.Visible = true;
else
literal.Visible = false;
DropDownList panelstyle = new DropDownList();
panelstyle.ID = "panelstyle";
panelstyle.CssClass = "panelstyle";
// panelstyle.Width = new Unit("100%");
panelstyle.AutoPostBack = true;
panelstyle.TextChanged -= new EventHandler(panelstyle_TextChanged);
panelstyle.TextChanged += new EventHandler(panelstyle_TextChanged);
this.Controls.Add(panelstyle);
if ((this.SearchPanelStyle & SearchPanelStyle.PanelStyleSwitch) == SearchPanelStyle.PanelStyleSwitch)
panelstyle.Visible = true;
else
panelstyle.Visible = false;
FillPanelStyleList(panelstyle);
literal = new LiteralControl("</td></tr>");
示例7: SetHyperLink
/// <summary>
/// 設置分頁連結
/// </summary>
/// <param name="currentPage"></param>
/// <param name="selectPage"></param>
/// <param name="totalPage"></param>
public static void SetHyperLink(PlaceHolder placeHolder, LinkButton pagingButton)
{
// 取得目前選擇的頁次與值
int nowPageValue = (pagingButton.CommandName == "*" ) ? int.Parse(pagingButton.ToolTip) : int.Parse(pagingButton.Text);
int nowPageIndex = int.Parse(pagingButton.ToolTip);
// 取得之前選擇的頁次與值
int lastPageValue = 0;
int lastPageIndex = 0;
for (int i = 1; i <= ((pds.PageCount > 10) ? 11 : pds.PageCount); i++)
{
LinkButton lb = (LinkButton)placeHolder.FindControl("_LinkButton" + i.ToString());
if (lb != null)
{
// 初始化
lb.Visible = true;
if (lb.Style.Count > 0 && lb.Style["text-decoration"].ToString() == "none")
{
lastPageValue = (pagingButton.CommandName == "*" ) ? int.Parse(pagingButton.ToolTip) : int.Parse(lb.Text);
lastPageIndex = int.Parse(lb.ToolTip);
}
}
}
// 新增位移的差距值
int offset = (nowPageValue - lastPageValue);
// 新的起始值是否小於0
bool isLow = false;
if (pagingButton.CommandName == "*" && pagingButton.ID == "_LinkButtonFirst")
{
for (int i = 1; i <= ((TotalPage >= 11) ? 11 : TotalPage); i++)
{
LinkButton lb = (LinkButton)placeHolder.FindControl("_LinkButton" + i.ToString());
lb.Text = i.ToString();
lb.CommandArgument = lb.Text;
lb.Style.Add("text-decoration", (i==1) ? "none" : "underline;");
if (int.Parse(lb.Text) > TotalPage) lb.Visible = false;
}
}
else if (pagingButton.CommandName == "*" && pagingButton.ID == "_LinkButtonLast")
{
for (int i = 1; i <= ((TotalPage >= 11) ? 11 : TotalPage); i++)
{
LinkButton lb = (LinkButton)placeHolder.FindControl("_LinkButton" + i.ToString());
lb.Text = (TotalPage - (( TotalPage < 6 ) ? TotalPage : 6 ) + i).ToString();
lb.CommandArgument = lb.Text;
lb.Style.Add("text-decoration", (int.Parse(lb.Text) == TotalPage) ? "none" : "underline;");
if (int.Parse(lb.Text) > TotalPage) lb.Visible = false;
}
}
else
{
// 如果是增值
if (offset > 0 && pagingButton.CommandName != "*")
{
if (lastPageValue == 1)
{
// 首次切換頁次
for (int i = 1; i <= ((TotalPage >= 11) ? 11 : TotalPage); i++)
{
LinkButton lb = (LinkButton)placeHolder.FindControl("_LinkButton" + i.ToString());
if (lastPageIndex < 6 && nowPageValue > 6)
lb.Text = (int.Parse(lb.Text) + (nowPageValue - 6)).ToString();
else
lb.Text = i.ToString();
lb.CommandArgument = lb.Text;
lb.Style.Add("text-decoration", (int.Parse(lb.Text) == nowPageValue) ? "none" : "underline;");
if (int.Parse(lb.Text) > TotalPage) lb.Visible = false;
}
}
else
{
// 非首次切換頁次
for (int i = 1; i <= ((TotalPage >= 11) ? 11 : TotalPage); i++)
{
LinkButton lb = (LinkButton)placeHolder.FindControl("_LinkButton" + i.ToString());
if (lastPageIndex == 6)
lb.Text = (int.Parse(lb.Text) + offset).ToString();
else if (lastPageIndex < 6 && nowPageValue > 6)
lb.Text = (int.Parse(lb.Text) + nowPageValue - 6).ToString();
else if (lastPageIndex < 6 && nowPageValue <= 6)
lb.Text = i.ToString();
else
lb.Text = (int.Parse(lb.Text) + offset - lastPageIndex).ToString();
//.........这里部分代码省略.........
示例8: fillObjectFromPlaceHolder
//create the opposite of createHtmlInputControl to handle control types when read
public bool fillObjectFromPlaceHolder(PlaceHolder placeholder)
{
Control currentControl;
foreach(DataRow row in _dbSchemas[this._dbTable].Rows) {
currentControl = placeholder.FindControl((row["ColumnName"]).ToString());
if (currentControl is CheckBox) {
this._dbData[row["ColumnName"].ToString()] = ((CheckBox)currentControl).Checked;
} else if (currentControl is TextBox) {
this._dbData[row["ColumnName"].ToString()] = ((TextBox)currentControl).Text;
} else if (currentControl is DropDownList) {
//throw new Exception(((DropDownList)currentControl).SelectedValue);
this._dbData[row["ColumnName"].ToString()] = ((DropDownList)currentControl).SelectedValue;
}
}
return true;
}