Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i pass the value (ID or text) of a label in a ASPX page to "Web User Control(ASCX)" page?
Answers with code are highly appreciated.



<%@ Register Src="~/MYA/test_web.ascx" TagPrefix="uc1" TagName="test_web" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">

 <uc1:test_web  runat="server" ID="test_web" />

    <asp:TextBox runat="server" ID="test" OnTextChanged="test_TextChanged"></asp:TextBox>
</asp:Content>




I want the textbox value in the test_web.ascx page. How shall i proceed?

Thanks in advance
Posted
Updated 17-Dec-14 1:14am
v2
Comments
KM Perumal 17-Dec-14 7:01am    
@divya : can you post your trying code???
Deepu S Nair 17-Dec-14 7:06am    
Please Check the question and try to improve it
Divya Aq 17-Dec-14 7:15am    
i have added the aspx code in my question. please let em know how can i proceed. do i need to add any piece of code in my ascx page?
KM Perumal 17-Dec-14 7:18am    
Want to pass value thru any event like textchange event??

1 solution

Create a property on your user control with the datatype of the data you want to pass to it, and populate it in your page on creation of the control.

C#
public class myUserControl : Control
    {
      ...
      public int myIntProperty {get; set;}
      ...
    }

Later this in the code behind you can assign the value like

C#
myUserControl cntrl = new myUserControl();
    cntrl.myIntProperty = test.text;

Instead of this you can pass the value through Markup also like
C#
<uc1:myUserControl ID="uc1" runat="server" myIntProperty="5" />
 
Share this answer
 

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