Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good Morning
I have a web user control which contain a html dropdownlist and a datalist(inside <div>).
on click of dropdownlist visible property of div is changed.for this i use javascript code as:
function Select1_onclick() {
       if (document.getElementById('<%=Context.Items["id"] %>').style.visibility != 'visible') {
           document.getElementById('<%=Context.Items["id"] %>').style.visibility = 'visible';
           document.getElementById('<%=Context.Items["id"] %>').style.display = 'block';
       }
       else {
           document.getElementById('<%=Context.Items["id"] %>').style.visibility = 'hidden';
           document.getElementById('<%=Context.Items["id"] %>').style.display = 'none';
       }
   }


where Context.Item["id"] contain id of div that is on webuser control.
on the form where i am placing that webuser control.
i initialise Context.Item["id"] as:
C#
public void wucWithdraw_Init(object sender, EventArgs e)
   {
              Context.Items["id"] = "ctl00_ContentPlaceHolder1_wucWithdraw_DivDL" (where wucWithdraw is id of web user control)
   }

It is working fine .
but when i places web user control two times on page then it retain only the last assigned value of Context.Item["id"].
Please provide me the way to do that.
Thanks
Posted

1 solution

Context.Items is shared by both the controls.

You can try like,

C#
Context.Items[string.Format("{0}_id",wucWithdraw.ClientID)]


for assigning values. (i.e), Use the ClientID of the Control appended along with the Key to get unique values.

So, What is this Context.Items for?
 
Share this answer
 
Comments
Sharma Richa 16-Mar-11 3:01am    
your answer is really useful but i am still in trouble. when i bebug the page at runtime source has two instances of javascript function as: 1.>>>. function Select1_onclick() { if (document.getElementById('ctl00_ContentPlaceHolder1_wucWithdraw_DivDL').style.visibility != 'visible') { document.getElementById('ctl00_ContentPlaceHolder1_wucWithdraw_DivDL').style.visibility = 'visible'; document.getElementById('ctl00_ContentPlaceHolder1_wucWithdraw_DivDL').style.display = 'block'; } else { document.getElementById('ctl00_ContentPlaceHolder1_wucWithdraw_DivDL').style.visibility = 'hidden'; document.getElementById('ctl00_ContentPlaceHolder1_wucWithdraw_DivDL').style.display = 'none'; } 2.>>>> function Select1_onclick() { if (document.getElementById('ctl00_ContentPlaceHolder1_wucDeposit_DivDL').style.visibility != 'visible') { document.getElementById('ctl00_ContentPlaceHolder1_wucDeposit_DivDL').style.visibility = 'visible'; document.getElementById('ctl00_ContentPlaceHolder1_wucDeposit_DivDL').style.display = 'block'; } else { document.getElementById('ctl00_ContentPlaceHolder1_wucDeposit_DivDL').style.visibility = 'hidden'; document.getElementById('ctl00_ContentPlaceHolder1_wucDeposit_DivDL').style.display = 'none'; } } } but problem is that when i click on the dropdownlist of wucWithdraw the onclick of wucDeposit is fired.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900