Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If You're getting the post back control id correctly but <code>FindControl</code> returns nothing, then it's probably because You're using a master page. Basically, <code>someControl.FindControl(id)</code> searches through controls that are in <code>someControl.NamingContainer</code> naming container. But in Your case, the <code>Button1</code> control is in the <code>ContentPlaceHolder1</code>, which is a naming container, and not directly in the <code>Page</code> naming container, so You won't find it by invoking <code>Page.FindControl</code>. If You can't predict in which naming container the control You're looking for is going to be (e.g. post back can be caused by two different buttons from two different content placeholders), then You can write an extension that'll search for a control recursively, like so:</p> <pre><code>public static class Extensions { public static Control FindControlRecursively(this Control control, string id) { if (control.ID == id) return control; Control result = default(Control); foreach (Control child in control.Controls) { result = child.FindControlRecursively(id); if (result != default(Control)) break; } return result; } } </code></pre> <p>Use it with caution though, because this method will return the first control that it finds with the specified id (and You can have multiple controls with the same id - but they <strong>should</strong> be in different naming containers; naming containers are meant to differentiate between controls with same ids, just as namespaces are meant to differentiate between classes with same names).</p> <p>Alternatively, You could try to use <code>FindControl(string id, int pathOffset)</code> overload, but I think it's pretty tricky.</p> <p>Also, check <a href="https://stackoverflow.com/questions/12579311/how-to-use-postbackurl-in-pages-with-masterpage">this question</a> out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload