Javascrpt and User Controls. Help!

Discussion in 'ASP .Net' started by =?Utf-8?B?ZXJpYw==?=, Nov 8, 2007.

  1. Hello,

    I'm trying to change a links href with javascript. I know that asp.net will
    change the controls ids to protect against multiple controls on a page. So I
    use the following code.

    var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;

    The problem is that imgLinkRead is a user control, so it is a control within
    a control. If I look at the source the id imgLinkRead is
    'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
    need help ASAP. Thanks
     
    =?Utf-8?B?ZXJpYw==?=, Nov 8, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?ZXJpYw==?=

    LVP Guest

    The same way Bind in Javascript
    or
    Inject your custom made Javascript to browser.

    you already have it.


    "eric" <> wrote in message
    news:...
    > Hello,
    >
    > I'm trying to change a links href with javascript. I know that asp.net
    > will
    > change the controls ids to protect against multiple controls on a page.
    > So I
    > use the following code.
    >
    > var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;
    >
    > The problem is that imgLinkRead is a user control, so it is a control
    > within
    > a control. If I look at the source the id imgLinkRead is
    > 'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
    > need help ASAP. Thanks
     
    LVP, Nov 8, 2007
    #2
    1. Advertising

  3. But it doesn't work. For some reason the ClientId doesn't return correct id.

    "LVP" wrote:

    > The same way Bind in Javascript
    > or
    > Inject your custom made Javascript to browser.
    >
    > you already have it.
    >
    >
    > "eric" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I'm trying to change a links href with javascript. I know that asp.net
    > > will
    > > change the controls ids to protect against multiple controls on a page.
    > > So I
    > > use the following code.
    > >
    > > var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;
    > >
    > > The problem is that imgLinkRead is a user control, so it is a control
    > > within
    > > a control. If I look at the source the id imgLinkRead is
    > > 'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
    > > need help ASAP. Thanks

    >
    >
    >
     
    =?Utf-8?B?ZXJpYw==?=, Nov 8, 2007
    #3
  4. The FindControl method operates on the immediate children of the Control you
    specify. If you want the ClientID of a Control inside the UserControl, you
    have to call FindControl on the UserControl. Example:

    ((UserControlName)this.FindControl("imgLinkRead")).FindControl("SomeControl").ClientID

    --
    HTH,

    Kevin Spencer
    Chicken Salad Surgeon
    Microsoft MVP

    "eric" <> wrote in message
    news:...
    > Hello,
    >
    > I'm trying to change a links href with javascript. I know that asp.net
    > will
    > change the controls ids to protect against multiple controls on a page.
    > So I
    > use the following code.
    >
    > var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;
    >
    > The problem is that imgLinkRead is a user control, so it is a control
    > within
    > a control. If I look at the source the id imgLinkRead is
    > 'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
    > need help ASAP. Thanks
     
    Kevin Spencer, Nov 8, 2007
    #4
  5. Thank you for the reply. If I try this code

    var clientId = <%=
    ((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID %>;

    ImageButtonLink being the control and imageLink being the hyperlink within
    the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
    that? Thanks again.

    "Kevin Spencer" wrote:

    > The FindControl method operates on the immediate children of the Control you
    > specify. If you want the ClientID of a Control inside the UserControl, you
    > have to call FindControl on the UserControl. Example:
    >
    > ((UserControlName)this.FindControl("imgLinkRead")).FindControl("SomeControl").ClientID
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Chicken Salad Surgeon
    > Microsoft MVP
    >
    > "eric" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I'm trying to change a links href with javascript. I know that asp.net
    > > will
    > > change the controls ids to protect against multiple controls on a page.
    > > So I
    > > use the following code.
    > >
    > > var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;
    > >
    > > The problem is that imgLinkRead is a user control, so it is a control
    > > within
    > > a control. If I look at the source the id imgLinkRead is
    > > 'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
    > > need help ASAP. Thanks

    >
    >
    >
     
    =?Utf-8?B?ZXJpYw==?=, Nov 8, 2007
    #5
  6. =?Utf-8?B?ZXJpYw==?=

    Guest

    hi,

    var objA = document.getElementById('<%= this.imgLinkRead.ClientID
    %>');
    objA.href = "www.someUrl.com";

    hope this can help.

    eric wrote:
    > Hello,
    >
    > I'm trying to change a links href with javascript. I know that asp.net will
    > change the controls ids to protect against multiple controls on a page. So I
    > use the following code.
    >
    > var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;
    >
    > The problem is that imgLinkRead is a user control, so it is a control within
    > a control. If I look at the source the id imgLinkRead is
    > 'Features1_imgLinkRead_imageLink'. How to I get that from javascript? I
    > need help ASAP. Thanks
     
    , Nov 9, 2007
    #6
  7. Hi eric,

    > var clientId = <%=
    > ((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID
    > %>;
    >
    > ImageButtonLink being the control and imageLink being the hyperlink within
    > the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
    > that? Thanks again.


    I couldn't say without seeing the actual code.

    --
    HTH,

    Kevin Spencer
    Chicken Salad Surgeon
    Microsoft MVP

    "eric" <> wrote in message
    news:...
    > Thank you for the reply. If I try this code
    >
    > var clientId = <%=
    > ((ImageButtonLink)this.FindControl("imgLinkRead")).FindControl("imageLink").ClientID
    > %>;
    >
    > ImageButtonLink being the control and imageLink being the hyperlink within
    > the ImageButtonLink, clientId returns the NavigationUrl. Why would it do
    > that? Thanks again.
    >
    > "Kevin Spencer" wrote:
    >
    >> The FindControl method operates on the immediate children of the Control
    >> you
    >> specify. If you want the ClientID of a Control inside the UserControl,
    >> you
    >> have to call FindControl on the UserControl. Example:
    >>
    >> ((UserControlName)this.FindControl("imgLinkRead")).FindControl("SomeControl").ClientID
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Chicken Salad Surgeon
    >> Microsoft MVP
    >>
    >> "eric" <> wrote in message
    >> news:...
    >> > Hello,
    >> >
    >> > I'm trying to change a links href with javascript. I know that asp.net
    >> > will
    >> > change the controls ids to protect against multiple controls on a page.
    >> > So I
    >> > use the following code.
    >> >
    >> > var buttonId = <%= this.FindControl("imgLinkRead").ClientID %>;
    >> >
    >> > The problem is that imgLinkRead is a user control, so it is a control
    >> > within
    >> > a control. If I look at the source the id imgLinkRead is
    >> > 'Features1_imgLinkRead_imageLink'. How to I get that from javascript?
    >> > I
    >> > need help ASAP. Thanks

    >>
    >>
    >>
     
    Kevin Spencer, Nov 9, 2007
    #7
    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. Rob Meade
    Replies:
    7
    Views:
    306
    Eliyahu Goldin
    Mar 18, 2007
  2. Faizan Ahmed
    Replies:
    1
    Views:
    288
    John Saunders
    Jan 4, 2005
  3. Howard Kaikow
    Replies:
    4
    Views:
    87
    Stewart Gordon
    Oct 12, 2004
  4. Grzegorz ¦lusarek

    javascrpt IDE

    Grzegorz ¦lusarek, May 11, 2006, in forum: Javascript
    Replies:
    3
    Views:
    99
    Thomas 'PointedEars' Lahn
    May 20, 2006
  5. globalrev

    insert javascrpt into textarea?

    globalrev, May 11, 2008, in forum: Javascript
    Replies:
    15
    Views:
    224
    Dr J R Stockton
    May 12, 2008
Loading...

Share This Page