Trying to call Method from control page

时间:2016-03-04 18:15:14

标签: c# asp.net webforms boolean

I have been trying to call a method from my .ascx.cs to my .aspx.cs codebehind. The routine will allow a check box on the .aspx page to hide/show a Textbox and Label on my user control page. Here is what I have so far. I have the visibility of Label and the Textbox set to false in properties.

control Page code behind:

public partial class Controls_udc : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private bool MakeVisible(object sender, EventArgs e)
    {
        return (labelComments.Visible == true) && (textComments.Visible == true);
    }

code behind for .aspx page:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        Controls_udc.MakeVisible();
    }

}

The compiler error I receive is Compiler Error Message: CS0117: 'Controls_udc' does not contain a definition for 'MakeVisible'.

I believe I am on the right track but just need a couple pointers.

1 个答案:

答案 0 :(得分:1)

MakeVisible方法必须为public,但在您的代码中为private。它应该改变。