Web User Control getting variable value

asp.net Saudi Arabia
  • 12 years ago

    I'm a novice in asp.net. I tried using a web user control with Dropdownlistbox and through with this dropdownlistbox I will choose any item on the list. Secondly, I create a new web form, through this web form (webform1.aspx)  I  drag my web user control. What I want now is, I want to get the value of selectedvalue from my dropdownlistbox from my web user control by retrieving the value on my webform1.aspx hoping somebody could help me with this problem.

     

    Thanks 

  • 12 years ago

    Here is a quit example.

    webform1.aspx

    <asp:DropDownList ID="myDropDownList" runat="server">

    <asp:ListItem Value="ValueItemOne">TextItemOne</asp:ListItem>

    <asp:ListItem Value="ValueItemTwo">TextItemTwo</asp:ListItem>

    </asp:DropDownList>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

    webform1.aspx.cs

    protected void Button1_Click(object sender, EventArgs e)

    {

    Label1.Text = myDropDownList.SelectedValue;

    }

  • 12 years ago

    take a look here:

    DropDownList mydrp=(DropDownList)ControlID.FindControl("DropDownID")

    this will get u the drop down. once u get it, do whatever u wabt to do with it.

    *ControlID=ID of the usercontrol 

    *DropDownID=ID of the dropdownlist

  • 12 years ago

    Dear Rajesh,

    I appreciate your solution regarding my problem and you got the idea what I want.  Unfortunately, when I try your solution by copying and paste and run your solution, the getvalue property of usercontrol11. show a null value in form1.cs . Hoping you could a better solution with this problem and appreciate your effort of helping me.

     Thanks

     


     

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”