Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I had created a user control in ASP.NET Which Contains a Label & DropdownList. I want to get the selected value of dropdownlist after the control is completelly loaded.
Anyone Plz Help me.


Thanks In Advance...
Posted
Updated 17-Nov-11 23:49pm
v2
Comments
Pandya Anil 18-Nov-11 5:41am    
you want to access in javascript or in code behind of page ?

1 solution

Create A property inside your User Control Like this

C#
public string mySelectedValue
{
  get
  {
     return ddlControl1.SelectedValue.toString();
  }
}


access the property in your page where you are using the UserControl like

C#
string strValue = UserControl1.mySelectedValue;


If you want to access the control at Client end (inside Javascript/jQuery), do the following
C#
protected void Page_Load(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript("strCtrlID","'" + ddlCtrl.ClientID + "'");
    //Rest of your page load logic.
}


JavaScript
document.getElementById(strCtrlID); 


cheaars :)
 
Share this answer
 
v2
Comments
Deshpande.anagha 18-Nov-11 7:07am    
Thanks For ur Reply. But I had one doubt... Where should i use document.getElementById(strCtrlID); & wat is strCtrlID?

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