hello i am trying to access textbox value which is inside usercontrol from content page.
i am using master page.
here is my user control
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AccessUser.ascx.cs" Inherits="UserControl_AccessUser" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
my content page- i am using master page
<uc1:AccessUser runat="server" ID="AccessUser" /> <br />
<asp:Label ID="Label1" runat="server" Text="No Data"></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Fetch TextBox Value from User Control" OnClick="Button1_Click" />
button click event
protected void Button1_Click(object sender, EventArgs e)
{
UserControl uc = this.Page.FindControl("AccessUser") as UserControl;
string name = (uc.FindControl("TextBox1") as TextBox).Text;
Label1.Text = name;
}
it gives error obejct reference not set