?
Solved

ASP.NET JavaScript problem

Posted on 2008-10-01
4
Medium Priority
?
188 Views
Last Modified: 2010-04-15
Hello there,

I have .ascx file in which I am adding dynamic Server controls based on the value from the database. I am running a loop and a set of controls are being created for each iteration. I've added some JavaScript code, which is working fine if I have a single set of controls. But the problem I am facing is that if I have more than 1 set of control, Javascript code is pointing to the previous set of code if the current one is clicked.

This could be happening because I am using the ID generated at the Client side, but I if I use the ID directly, it is not working. I am registering the following code with the page with the help of Page.ClientScript.RegisterClientScriptBlock.

Does anyone have an idea, how to fix this?

Thanks,
function descLabel_Click() 
{
document.getElementById('ctl00_mainContent_documentList_descTextBox').value = 'Add Description here';
document.getElementById('ctl00_mainContent_documentList_descLabel').style.display = 'none';
document.getElementById('ctl00_mainContent_documentList_descTextBox').style.display = '';
document.getElementById('ctl00_mainContent_documentList_descTextBox').focus();
}
 
function descTextBox_Blur()
{ 
document.getElementById('ctl00_mainContent_documentList_descTextBox').style.display = 'none';
document.getElementById('ctl00_mainContent_documentList_descLabel').style.display = '';                        
document.getElementById('ctl00_mainContent_documentList_descLabel').innerHTML = document.getElementById('ctl00_mainContent_documentList_descTextBox').value;
}

Open in new window

0
Comment
Question by:ganeshji007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Onthrax earned 1000 total points
ID: 22614026
You can use the ClientID property to reference the generated client ID.

http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx

Hope this helps :)
0
 
LVL 13

Expert Comment

by:Onthrax
ID: 22614034
Here's an example if you require one:

http://www.devx.com/tips/Tip/28332
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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