Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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
ASP.net委托函数获取的控件值不正确_Asp.net_Delegates_Web Controls_Asp.net 4.5 - Fatal编程技术网

ASP.net委托函数获取的控件值不正确

ASP.net委托函数获取的控件值不正确,asp.net,delegates,web-controls,asp.net-4.5,Asp.net,Delegates,Web Controls,Asp.net 4.5,我们在我们的站点上有一些函数调用,如果是有条件的,那么我们就用委托函数来代替它们,问题是现在在函数调用中,控件值总是第一个,比如它的缓存值。原因可能是什么 最好在初始化时设置委托,或者每次使用if调用正确的函数 简化示例: aspx: <form runat="server" id="form1"> <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" CombineScr

我们在我们的站点上有一些函数调用,如果是有条件的,那么我们就用委托函数来代替它们,问题是现在在函数调用中,控件值总是第一个,比如它的缓存值。原因可能是什么

最好在初始化时设置委托,或者每次使用if调用正确的函数

简化示例:

aspx:

<form runat="server" id="form1">
    <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" CombineScripts="False" EnableScriptGlobalization="True" EnableScriptLocalization="True" EnablePageMethods="True"></ajaxToolkit:ToolkitScriptManager>

    <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>
            <asp:CheckBox ID="cbViewPrinted" Text="View printed docs" runat="server" />
            <asp:Button ID="btnFilter" runat="server" OnClick="btnFilter_Click"  />
        </ContentTemplate>
    </asp:UpdatePanel>
</form>
private delegate void LoadDataFuncx();
private LoadDataFuncx LoadData
{
    get
    {
        (LoadDataFuncx)Session["LoadData"];
    }
    set
    {
       Session["LoadData"]=value;
    }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Initialize();
    }
}

private void Initialize()
{
    if(conditionx==true)
    {
        LoadData=LoadDataCaseA;
    }
    else
    {
        LoadData=LoadDataCaseB;
    } 
}

private void LoadDataCaseA()
{
   //if called from delegate this always is false (even when the user checked the control or i set the value to checked by code later...)
   bool viewprinted=cbViewPrinted.Checked;
}

private void LoadDataCaseB()
{
   //if called from delegate this always is false (even when the user checked the control or i set the value to checked by code later...)
   bool viewprinted=cbViewPrinted.Checked;
}

protected void btnFilter_Click(object sender, EventArgs e)
{
    LoadData(); //calling from delegate...always gets the first control values (cached?) :S

    if(conditionx==true) //direct calling by checking condition, gets the current control value (correct)
    {
        LoadDataCaseA();
    }
    else
    {
        LoadDataCaseB();
    } 
}