|
-
Nov 25th, 2004, 04:54 PM
#1
Thread Starter
Hyperactive Member
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.
-
Nov 25th, 2004, 10:27 PM
#2
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 : 
-
Nov 26th, 2004, 04:40 AM
#3
Thread Starter
Hyperactive Member
-
Nov 26th, 2004, 04:55 AM
#4
Thread Starter
Hyperactive Member
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
-
Nov 26th, 2004, 06:21 AM
#5
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 : 
-
Nov 26th, 2004, 06:47 AM
#6
Thread Starter
Hyperactive Member
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.
-
Nov 26th, 2004, 07:16 AM
#7
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 : 
-
Nov 26th, 2004, 07:29 AM
#8
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 : 
-
Nov 26th, 2004, 09:06 AM
#9
Thread Starter
Hyperactive Member
Ahh sweet I will give that a go :-)
You spelt var wrong :-P
-
Nov 26th, 2004, 10:20 AM
#10
Thread Starter
Hyperactive Member
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!!
-
Nov 26th, 2004, 10:46 AM
#11
Thread Starter
Hyperactive Member
Its also just occured to me that the code is cycling through the forms elements. I'm hunting for a <tr> and and <img>
-
Nov 26th, 2004, 11:23 AM
#12
Thread Starter
Hyperactive Member
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";
}
}
-
Nov 26th, 2004, 02:59 PM
#13
-
Nov 29th, 2004, 04:40 AM
#14
Thread Starter
Hyperactive Member
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
-
Nov 29th, 2004, 08:02 AM
#15
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|