Solved

ASP.NET JavaScript problem

Posted on 2008-10-01
4
174 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
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Onthrax earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now