findcontrol

Find a control on a page with a master page

懵懂的女人 提交于 2019-11-26 17:14:05
问题 I have to find a Control in an aspx page bound to a master page. The master page contains: <asp:ContentPlaceHolder ID="MainContent" runat="server"/> The content page contains: <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> </asp:Content> I added a Table with ID formtable as a child of Content2 . I tried to use the following code to access the Table , but the code returns

Find all child controls of specific type using Enumerable.OfType<T>() or LINQ

橙三吉。 提交于 2019-11-26 11:15:13
问题 Existed MyControl1.Controls.OfType<RadioButton>() searches only thru initial collection and do not enters to children. Is it possible to find all child controls of specific type using Enumerable.OfType<T>() or LINQ without writing own recursive method? Like this. 回答1: I use an extension method to flatten control hierarchy and then apply filters, so that's using own recursive method. The method looks like this public static IEnumerable<Control> FlattenChildren(this Control control) { var

C#, FindControl [duplicate]

亡梦爱人 提交于 2019-11-26 08:30:10
问题 This question already has answers here : Better way to find control in ASP.NET (8 answers) Closed last year . I\'m sorry, but I can\'t understand why this doesn\'t work. After compile, I receive a \"Null reference exception\". Please help. public partial class labs_test : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text != \"\") { Label Label1 = (Label)Master.FindControl(\"Label1\"); Label1.Text = \"<b>The text you entered was: \" + TextBox1

How to find controls in a repeater header or footer

家住魔仙堡 提交于 2019-11-26 07:56:40
问题 I was wondering how one would find the controls in the HeaderTemplate or FooterTemplate of an Asp.Net Repeater control. I can access them on the ItemDataBound event, but I was wondering how to get them after (for example to retrieve a value of an input in the header/footer). Note: I posted this question here after finding the answer just so that I remember it (and maybe other people might find this useful). 回答1: As noted in the comments, this only works AFTER you've DataBound your repeater.

Finding control within WPF itemscontrol

喜夏-厌秋 提交于 2019-11-26 07:35:35
问题 Hi i have few a single textbox within the the datatemplate for itemscontrol. When i bind the itemcontrols to a observable collection i get two text boxes. But i need to do some manipulations based on each of the text boxes for which i want to find each textbox seperatly using some id. Can anybody help on how to find a control witin the itemscontrol in WPF. 回答1: Using the ItemContainerGenerator you can obtain the generated container for an item and traverse the visual tree downwards to find

How to find Control in TemplateField of GridView?

隐身守侯 提交于 2019-11-26 03:34:54
问题 How does FindControl method works if I need to find any Control which is inside GridView Template , more specifically ItemTemplate ? I have a hyperlink but it is not able to find the same. Question updated with code GridView Code is below: <asp:GridView ID=\"grvYourOpportunities\" runat=\"server\" AllowPaging=\"True\" AutoGenerateColumns=\"False\" DataKeyNames=\"ID#,B,H\" PageSize=\"20\" CellPadding=\"4\" ForeColor=\"#333333\" GridLines=\"Both\" OnRowDataBound=\"grvYourOpt_RowDataBound\">

Better way to find control in ASP.NET

天涯浪子 提交于 2019-11-25 22:30:53
问题 I have a complex asp.net form,having even 50 to 60 fields in one form like there is Multiview , inside MultiView I have a GridView , and inside GridView I have several CheckBoxes . Currently I am using chaining of the FindControl() method and retrieving the child ID. Now, my question is that is there any other way/solution to find the nested control in ASP.NET. 回答1: If you're looking for a specific type of control you could use a recursive loop like this one - http://weblogs.asp.net/eporter