Results 1 to 15 of 15

Thread: Establishing Control Name [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Resolved Establishing Control Name [RESOLVED]

    Hi all,

    I'm setting the ID of a server control tables' row to example "MyRow" and being that the table is on a control within a control the resulting id comes out as:

    id="cntTOrdersList_ctlTOrdersList_MyRow"

    I've added javascript at runtime to point to 'MyRow' but its not finding it using Document.All.MyRow which makes sense

    How can I establish the full name (as above) in the code? I cant see how its even possible? Failing that, anyone know any javascript to find it?

    This is universal code so I can't cheat and just add "cntTOrdersList_ctlTOrdersList_" :-)

    Thanks
    Last edited by tailz; Nov 26th, 2004 at 11:24 AM.

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    I had the same problem a while back, I found out that you can use the ClientID property of the control to get the modified name and then use that to refence it. Search for ClientID property you should find exmaple. If not then let me know, i will dig out my 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 :

  3. #3

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    Thanks for replying

    The ClientID is just returning the ID.

    I am reading the ID of the Webcontrols.Image in question before its been added to the TableCell's control collection and before the Table has been added the usercontrol though so I'd understand if it didnt know wot the parents were

    I'll tinker with it for a bit, prolly just need to change the way code works. Sooo tired am falling asleep at desk here so may take a while

    Cheers

    (and I found your post

    http://www.vbforums.com/showthread.p...light=ClientID )
    Last edited by tailz; Nov 26th, 2004 at 04:43 AM.

  4. #4

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    I'm guessing you were using static controls when you asked your question?

    Dunt think I can modify meh code to work without some evil bodge job

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by tailz
    I'm guessing you were using static controls when you asked your question?

    Dunt think I can modify meh code to work without some evil bodge job
    Correct me if i am wrong but all you need is the prefix, so i dynamically write a javascript variable which contain the prefix of the parent control then use something like eval(document.all. + prefix + myRow) ...........

    In your case the prefix wold be cntTOrdersList_ctlTOrdersList_

    Hope this make sense...
    [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 :

  6. #6

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    Ya makes sense.

    The variable approach would be ok but there will be several parents containing various objects that call this function and it would get real messy I think.

    Don't suppose you know how to "find" a control in javascript or just iterate through the control list and look for " Like '*MyControl' " then all I would have to do is tweak my function. All the control names are unique despite diff parents so that won't be an issue.

    On other note, I've just installed FireFox and the thing doesnt render some of my stuff properly Seems to have an issue with tables in tables.

  7. #7
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Yes, using javascript you can loop through all the controls with in a form. You can check the name property and use indexOf function to check it is the control you are looking for. If you need example i will have to give it to you when i get home.

    Also are you aware that you can dynmically inject Javascript to a controls/page from ASP.Net Serverside code? You can do it through Attributes of a HTMLControl/WebFormControl. This might do away with all the messing with ClientID and other nasty javascript..

    FireFox has big issues with VS.Net generated HTML code. Unfortunately it is not the fault of FireFox well in most cases. In many cases i have to modify html code manually to make it render properyly in FireFox. I doubt MS would be too keen on fixing these issues as a priority. Just have to tell our client to use IE for the time being.

    Danial
    [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 :

  8. #8
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Here is the javascript that you need to iterate through the controls.

    I have just put it together, didnt get a chance to test it, so might have small error in it.

    Code:
     for (var i = 0; i < document.form1.elements.length; i++)
    	{
    		var e = document.form1.elements[i];
    		ver strName;
    
    		
    		tmpStr = e.name;
    
    		if (tmpStr.indexOf("myControl")>0)
    		{		
    			//your control found
    			strName=e.name;
    			break;
    		}
    
    			
    		
    
    
    
    	}
    [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 :

  9. #9

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    Ahh sweet I will give that a go :-)

    You spelt var wrong :-P


  10. #10

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    When you talk about injecting javascript, I assume that means adding it at runtime?

    I am aware of this but surely just adding it at runtime will not help as I'd still need to know the full name of the control?

    I'm having a mare with that code u gave me as well but I'll play with it some more so I actually learn summat

    Cheers for all your help so far!!

  11. #11

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    Its also just occured to me that the code is cycling through the forms elements. I'm hunting for a <tr> and and <img>


  12. #12

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Resolved

    Got it to do what I wanted.

    I pasted a cut down version of the function I produced in case its ever any use to anyone.

    All it does is hide a TableRow given a partial ID

    Thanks for your help Danial - 10/10

    Code:
    function EC(TheTR){
      var sTRname;
      var objs = document.getElementsByTagName("tr");
      for (var i = 0; i < objs.length; i++) {
        var tmpStr = objs[i].id;
        if (tmpStr.indexOf(TheTR)>0){		
          sTRname=tmpStr;
          break;
        }
      }	
      var DataTR = document.getElementById(sTRname);
      if (DataTR.style.display=="block" || DataTR.style.display=="") {
        DataTR.style.display="none";
      }
      else {
        DataTR.style.display="block";
      }
    }

  13. #13
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Glad it worked for you.

    If were hiding table row you should have told me, i used almost the same kind of code to the exact same thing .

    Note that i recently checked it on FireFox and it looks messed up so have to re-write the code. Does your code work in firefox? Or is it not an issue for you.
    [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 :

  14. #14

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306
    Yea hiding a table row + an image, just making a collapsable table.

    As for firefox. lol.

    Aside from the layout being totally messed up the code when I click the button does make the row visible / invisible.

    However, on expand, it will push all items below it down (as it should) but on collapse it does not bring them back up. (Make sense?). Looks like a bug to me

  15. #15
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by tailz
    Yea hiding a table row + an image, just making a collapsable table.

    As for firefox. lol.

    Aside from the layout being totally messed up the code when I click the button does make the row visible / invisible.

    However, on expand, it will push all items below it down (as it should) but on collapse it does not bring them back up. (Make sense?). Looks like a bug to me
    Yes I have done the same sort of thing but in ASP not in asp.net.

    I get exactly the same problem with FireFox, it expands fine but when I collapse it, it does not remove the space those rows was occupying. Leaves a nasty blue blacground color.

    Guess I will have to go FF/IE compatible JavaScript hunting...

    Anywa glad your problem is fixed. I am outa here

    [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