[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sending Client ID's To Javascript from Nested Controls

Posted on 2009-02-13
11
Medium Priority
?
706 Views
Last Modified: 2013-12-17
SO this is what i am doing, i need to provide the customer with for lack of a better word three tiered grouping control. So to explain I have two levels of groupings, there is a super high level, the user the clicks on that and it expands to the next leve. The user can then expand one further and there is the details. The detail row constists of the record information and it gives the users the ability to sort these projects. So what i did to accomplish this was use a table defined in the aspx call the database and get all the rows for that table, then for each individual row i would add the additional rows and then check to see if there were any child rows. If so i would call the database and then build another table with the second tier of information. I subsequently do the same where i check to see if there are any details for that. If so i add a user control i created ( a gridview) and then bind it with information. I handle the collapsing and expanding through javascript. So this all works but what i need to happed is there is a text box  and a drop down that i need to fire a javascript funtion when the values are changed. I am adding this code in the user control code behind using the attributes.add("onchange", "Function( " + control.ClientID +")" but when the event fires it says that the control does not exist , when i view source the client side control name does not match with what is the function is receiving. I am building the controls on the Init so i would think it would not be a problem. I can provid the code if that would help
0
Comment
Question by:Steege
  • 5
  • 5
11 Comments
 
LVL 16

Expert Comment

by:sunithnair
ID: 23637988
Try like this
Code behind inside Griview_RowDataBoundEvent
 
e.Row.FindControl("ControlName").Attributes.Add("onchange", "JFunction( '" + control.ClientID +"')")
 
JavaScript
<script language='javascript'>
function JFunction(src)
{
  var control = document.getElementById(src);
  //do whatever you want with the "control" now
}
</script>

Open in new window

0
 

Author Comment

by:Steege
ID: 23638049
Then i get 'null' is null or not an object,. i found some code that does work to find the cotrol, but there are often lots of controls to look through so if the control being changed is at the end of the list it does take a while to make the change. I was using a cotrol that i found off the web called HierarGrid which allows you to nest gridviews but the page size ended up getting pretty bloated. i am using the same control and it worked before so i cant see what i am doing wrong with this one
function findObjWithClientId(Id)

{

var ctrls = document.all;

for(var count = 0; count < ctrls.length ; count ++)

{

var index = ctrls[count].id.indexOf(Id);

if(index != -1)

{

if((ctrls[count].id.length - index) == Id.length)

{

return ctrls[count];

}

}

}

return null;
}
0
 
LVL 16

Expert Comment

by:sunithnair
ID: 23638155
This is the better way of doing it. dociment.all only works in IE use getElementById instead
function findObjWithClientId(Id)
{
  return document.getElementById(Id);
}

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:Steege
ID: 23638204
I get a Then i get 'null' is null or not an object when i use that fundtion
0
 
LVL 16

Expert Comment

by:sunithnair
ID: 23638248
Try putting an alert in the function and see what is the output and see if that element exists in the html source
function findObjWithClientId(Id)
{
  alert(Id);
  return document.getElementById(Id);
}

Open in new window

0
 

Author Comment

by:Steege
ID: 23638273
its is not in the html source it exists there as id="ctl00_ContentPlaceHolder1_gvDetails_gvDetails_ctl02_sbPriorityRanking"   can i assume that the ctl00_ContentPlaceHolder1_gvDetails will always be there?
0
 
LVL 16

Accepted Solution

by:
sunithnair earned 400 total points
ID: 23638381
If it does not exist in the html then it will retun null.
0
 

Author Comment

by:Steege
ID: 23638419
i could just add the ContentPlaceHolder1_ to the string and it should find it
0
 
LVL 16

Expert Comment

by:sunithnair
ID: 23638478
yes try doing that
0
 

Author Comment

by:Steege
ID: 23638481
that does work, i am guessing "ContentPlaceHolder1_ " should be consistent
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23643333
Anytime you use a masterpage, "ctl00_ContentPlaceHolder1_" is going to be before your control name.

ctl00 is the default name for the Form container that the content place holder is in.

So it goes FormID_ContentID_ControlID




0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question