Results 1 to 5 of 5

Thread: ID/Name of controls in UserControl [resolved]

  1. #1

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    ID/Name of controls in UserControl [resolved]

    Hi,
    I am creating some custom ASP.net controls as Web User Control.I have client side scripting within those control. Now when i place those control with in an aspx control the Name/ID of the element(textbox, buttons) are renamed with a prefiex e.g ControlName_.

    Now since the ID/Name of the control has been changed now my client side script wont work. For example if i have a control called txtInput and my Web User Control is named AddEvent, txtInput is now renamed as AddEvent1_txtInput.

    How can I refrence this txtInput ?


    Thanks for any help.

    BTW : I am using C# as my ASP.net language.
    Last edited by Danial; Aug 29th, 2004 at 09:56 AM.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  2. #2
    There are a few different ways to handle it depending on what you are trying to do.

    If I remember correctly, all you really need to do is write a javascript variable from ASP.NET that contains the name of the FIRST control (or use a hidden field). Then you know every subsequent control will be name_control2..3...4...
    So you just plan for that in your Javascript code.

    There is also a rendering output for the ASP.NET control, so you can use that to inject javascript code directly into ASP.NET. Therefore, you can just have ASP.NET create a Javascript array that contains all instances of the control names. Then javascript can use that array.

    There is also a .NET class (dont remember the name) that allows you to inject javascript into the page in a more manageable way. It is documented in the help, but it is a little hard to find and I cannot remember the exact name of it.

    Hope this helps...
    Last edited by DHC Web Hosting; Aug 28th, 2004 at 10:59 PM.
    Developer Web Hosting - ASP.NET & PHP
    www.datahostingcenter.com
    15% OFF HOSTING Coupon for Forum Members - Enter:
    vbforums

  3. #3

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Fuond a easier way. The property ClientID gives the modified name of a given control.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  4. #4
    Hmm I must have misunderstood you, because if you solved it with the ClientID property, then it sounds like your problem was more how to know the instance name in ASP.NET rather then how to tell Javascript the instance name. I guess once you knew the instance name in ASP.NET, you already knew the rest of the solution.

    Now since the ID/Name of the control has been changed now my client side script wont work.
    The way you described it, I assumed your problem was more how to reference the control from Javascript, not from ASP.NET. The problem would still exist of getting the ASP.NET name back over to Javascript until "ASP.NET sends Javascript the name" such as in a list of names in an injected array or by using ASP.NET's javascript rendering class/injector.

    I guess your problem wasn't "teaching" Javascript the name of the control, but rather getting the "INSTANCE" name of the control from ASP.NET itself?
    Last edited by DHC Web Hosting; Aug 30th, 2004 at 01:26 AM.
    Developer Web Hosting - ASP.NET & PHP
    www.datahostingcenter.com
    15% OFF HOSTING Coupon for Forum Members - Enter:
    vbforums

  5. #5

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    The way you described it, I assumed your problem was more how to reference the control from Javascript, not from ASP.NET. The problem would still exist of getting the ASP.NET name back over to Javascript until "ASP.NET sends Javascript the name" such as in a list of names in an injected array or by using ASP.NET's javascript rendering class/injector.

    I guess your problem wasn't "teaching" Javascript the name of the control, but rather getting the "INSTANCE" name of the control from ASP.NET itself?
    I simply store the Instance name of the usercontrol in a variable, and dynamically prefiex the id to my javascript code.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width