Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用户控件内的asp.net更新面板不工作_C#_Asp.net_Updatepanel - Fatal编程技术网

C# 用户控件内的asp.net更新面板不工作

C# 用户控件内的asp.net更新面板不工作,c#,asp.net,updatepanel,C#,Asp.net,Updatepanel,我正在开发一个asp.net/C#web应用程序 在主页中: 我在更新面板中有一个占位符 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click"/> </Triggers&

我正在开发一个asp.net/C#web应用程序

在主页中: 我在更新面板中有一个占位符

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click"/>
    </Triggers>
    <ContentTemplate>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server">
        </asp:PlaceHolder>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:CheckBox ID="CheckBox1" Checked="true" Text="View" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" />
在我正在加载的控件中,我放置了一个更新面板,该面板由控件中的复选框触发

在MyControl中: 问题是: 从主页面,当我点击LinkButton1时,控制加载正确,一切正常。 但是,当我单击控件的复选框时,它不会像我希望的那样更新内部更新面板。控件刚从主页上消失

非常感谢您的帮助。
提前感谢,我希望我说得很清楚

您需要在page onload事件中创建用户控件并将其隐藏。建议您在此处创建控件,并使用“链接”按钮使其可见并设置其他属性

   protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        //-- Create your controls here
    }
在后面试试我的代码

Default.cs

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["isLoad"] == null) return;
        if (Session["isLoad"].ToString() == "1")
        {
            PlaceHolder1.Controls.Clear();
            Control CC = LoadControl("MyControl.ascx");
            PlaceHolder1.Controls.Add(CC);
        }
    }

    protected void Link1_Click(object sender, EventArgs e)
    {
        Session["isLoad"] = "1";
        Response.Redirect(Request.RawUrl);
    }
}
MyControl.cs

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

    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        //Do the update on the controls that are in the update panel
        if(CheckBox1.Checked)
            lblMessage.Text = "Hello";
        else
            lblMessage.Text = "Goodbye";
    }
}

你的asp:ScriptManager在哪里?@gillyb:请详细说明。这个评论没用。我的scriptmanager在主页上。
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    //Do the update on the controls that are in the update panel
}
   protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        //-- Create your controls here
    }
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["isLoad"] == null) return;
        if (Session["isLoad"].ToString() == "1")
        {
            PlaceHolder1.Controls.Clear();
            Control CC = LoadControl("MyControl.ascx");
            PlaceHolder1.Controls.Add(CC);
        }
    }

    protected void Link1_Click(object sender, EventArgs e)
    {
        Session["isLoad"] = "1";
        Response.Redirect(Request.RawUrl);
    }
}
public partial class MyControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        //Do the update on the controls that are in the update panel
        if(CheckBox1.Checked)
            lblMessage.Text = "Hello";
        else
            lblMessage.Text = "Goodbye";
    }
}