FindControl() Question

Discussion in 'ASP .Net' started by DotNet, Feb 12, 2004.

  1. DotNet

    DotNet Guest

    I'd like to capture an attribute of one control from another control called
    in the same ASPX page. I can get the ID value, but no other attributes. How
    does one do this?

    Control MyControl = Parent.FindControl("HeaderTemplate");
    if(MyControl != null) {
    Response.Write("Value: " + MyControl.ID); //this works fine.
    Response.Write("Value: " + MyControl.Section); //this doesn't
    work!
    Response.Write("Value: " + MyControl.Attributes("Section"));
    //this doesn't work either!
    }

    Thanks.
    DotNet, Feb 12, 2004
    #1
    1. Advertising

  2. Hi,

    You have to cast the HeaderTemplate object.
    For instance if HeaderTemplate is a DataGrid, you have to cast it to the
    datagrid type and then use it.

    ((DataGrig)HeaderTemplate).AnyPropertYouWishToUse

    Hope this helps.

    Stefano Mostarda MCP
    Rome Italy

    DotNet wrote:
    > I'd like to capture an attribute of one control from another control called
    > in the same ASPX page. I can get the ID value, but no other attributes. How
    > does one do this?
    >
    > Control MyControl = Parent.FindControl("HeaderTemplate");
    > if(MyControl != null) {
    > Response.Write("Value: " + MyControl.ID); //this works fine.
    > Response.Write("Value: " + MyControl.Section); //this doesn't
    > work!
    > Response.Write("Value: " + MyControl.Attributes("Section"));
    > //this doesn't work either!
    > }
    >
    > Thanks.
    >
    >
    Stefano Mostarda, Feb 12, 2004
    #2
    1. Advertising

  3. DotNet

    DotNet Guest

    Excellent!. Thanks very much. Worked like a charm.



    "Stefano Mostarda" <> wrote in message
    news:...
    > Hi,
    >
    > You have to cast the HeaderTemplate object.
    > For instance if HeaderTemplate is a DataGrid, you have to cast it to the
    > datagrid type and then use it.
    >
    > ((DataGrig)HeaderTemplate).AnyPropertYouWishToUse
    >
    > Hope this helps.
    >
    > Stefano Mostarda MCP
    > Rome Italy
    >
    > DotNet wrote:
    > > I'd like to capture an attribute of one control from another control

    called
    > > in the same ASPX page. I can get the ID value, but no other attributes.

    How
    > > does one do this?
    > >
    > > Control MyControl = Parent.FindControl("HeaderTemplate");
    > > if(MyControl != null) {
    > > Response.Write("Value: " + MyControl.ID); //this works

    fine.
    > > Response.Write("Value: " + MyControl.Section); //this

    doesn't
    > > work!
    > > Response.Write("Value: " + MyControl.Attributes("Section"));
    > > //this doesn't work either!
    > > }
    > >
    > > Thanks.
    > >
    > >
    DotNet, Feb 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Durzi

    OnEditCommand - .FindControl Returning Null

    George Durzi, Jul 14, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    478
    George Durzi
    Jul 14, 2003
  2. Ravikanth[MVP]

    FindControl

    Ravikanth[MVP], Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    442
    Yan-Hong Huang[MSFT]
    Jul 22, 2003
  3. James G. Beldock
    Replies:
    1
    Views:
    9,301
    Kevin Spencer
    Aug 7, 2003
  4. Teemu Keiski

    FindControl Question

    Teemu Keiski, Jan 15, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,973
    Kevin Spencer
    Jan 15, 2004
  5. Roshawn Dawson

    FindControl Question

    Roshawn Dawson, Mar 17, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    102
    Steve C. Orr [MVP, MCSD]
    Mar 17, 2005
Loading...

Share This Page