为什么没有在UpdatePanel发现更新数据 [英] Why isn't the UpdatePanel found to update the data

查看:520
本文介绍了为什么没有在UpdatePanel发现更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code在我的ASP.net页:

I have the following code in my ASP.net page:

<asp:UpdatePanel runat="server" ClientIDMode="Static" UpdateMode="Conditional" ID="upClickShowTask">
    <ContentTemplate>
        <asp:LinkButton ID="lbShowTask" CssClass="btnExport" ClientIDMode="Static" runat="server" Text="Generate Tasks" OnClick="btnFilter_Click"></asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:Panel ID="pageTab8" ClientIDMode="Static" runat="server">
    <asp:Panel ID="demoCli" ClientIDMode="Static" runat="server" BorderWidth="2" BorderColor="#FF0000">
        <asp:UpdatePanel ID="upGenTaskCli" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
            <ContentTemplate>
                Client: <asp:Label ID="lblCli" ClientIDMode="Static" runat="server" Text=""></asp:Label>
                <br />
                Onboarding Date: <asp:Label ID="lblCliDate" ClientIDMode="Static" runat="server" Text=""></asp:Label>
                <br />
                Contact Information: <asp:Label ID="lblCliCont" ClientIDMode="Static" runat="server" Text=""></asp:Label>
                <br />
                Notes: <asp:Label ID="lblCliNotes" runat="server" ClientIDMode="Static" Text=""></asp:Label>
                <br />
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Panel>
</asp:Panel>

在code-背后:

The code-behind:

protected void btnFilter_Click(object sender, EventArgs e)
{

    demoCli.Visible = false;
    demoSit.Visible = false;
    demoPra.Visible = false;
    demoPro.Visible = false;
        connString = @""; //my connection string
        #region queries
        string queryCli = @"SELECT
                           C.OBJECTID
                           ,C.ATTR2815 'Client'
                           ,C.ATTR2881 'Onboarding Date'
                           ,C.ATTR2880 'Contact Information'
                           ,M.MEMO 'Notes'
                            FROM HSI.RMOBJECTINSTANCE1231 C INNER JOIN HSI.RMMEMO M ON C.MK2879 = M.MEMOID";
        string querySit = @"SELECT
                           S.OBJECTID
                           ,S.ATTR2819 'Site'
                           ,S.FK2820 'RelatedClient'
                           ,S.ATTR2873 'Address'
                           ,S.ATTR2874 'City'
                           ,S.ATTR2875 'State'
                           ,S.ATTR2876 'Zip'
                           ,M.MEMO 'Notes'
                           ,S.ATTR2878 'Onboarding Date'
                            FROM HSI.RMOBJECTINSTANCE1229 S INNER JOIN HSI.RMMEMO M ON S.MK2877 = M.MEMOID";
        string queryPra = @"SELECT
                           P.OBJECTID
                           ,P.ATTR2817 'Practice'
                           ,P.FK2818 'RelatedSite'
                           ,P.ATTR2882 'Onboarding Date'
                           ,M.MEMO 'Notes'
                            FROM HSI.RMOBJECTINSTANCE1230 P INNER JOIN HSI.RMMEMO M ON P.FK2818 = M.MEMOID";
        string queryPro = @"SELECT 
                           P.OBJECTID
                           ,P.ATTR2919 'Provider'
                           ,P.ATTR2920 'Start Date'
                           ,P.FK2921 'RelatedPractice'
                           ,P.FK2922 'RelatedClient'
                            FROM HSI.RMOBJECTINSTANCE1249 P";
        #endregion 


        string query = "";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            if (ddlCli.SelectedIndex > 0)
            {
                try
                {
                    demoCli.Visible = true;

                    query = queryCli + " WHERE C.ATTR2815 = '" + ddlCli.SelectedValue + "'";

                    // create data adapter
                    SqlDataAdapter da = new SqlDataAdapter(query, conn);
                    // this will query your database and return the result to your datatable

                    DataSet myDataSet = new DataSet();
                    da.Fill(myDataSet);
                    lblCli.Text = myDataSet.Tables[0].Rows[0]["Client"].ToString();
                    lblCliDate.Text = myDataSet.Tables[0].Rows[0]["Onboarding Date"].ToString();
                    lblCliCont.Text = myDataSet.Tables[0].Rows[0]["Contact Information"].ToString();
                    lblCliNotes.Text = myDataSet.Tables[0].Rows[0]["Notes"].ToString();

                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                }
            }

            if (ddlSit.SelectedIndex > 0)
            {
                try
                {
                    demoSit.Visible = true;
                    query = querySit + " WHERE S.ATTR2819 = '" + ddlSit.SelectedValue + "'";

                    // create data adapter
                    SqlDataAdapter da = new SqlDataAdapter(query, conn);
                    // this will query your database and return the result to your datatable

                    DataSet myDataSet = new DataSet();
                    da.Fill(myDataSet);
                    lblSit.Text = myDataSet.Tables[0].Rows[0]["Site"].ToString();
                    lblSitRC.Text = myDataSet.Tables[0].Rows[0]["RelatedClient"].ToString();
                    lblSitAdd.Text = myDataSet.Tables[0].Rows[0]["Address"].ToString();
                    lblSitCity.Text = myDataSet.Tables[0].Rows[0]["City"].ToString();
                    lblSitSt.Text = myDataSet.Tables[0].Rows[0]["State"].ToString();
                    lblSitzip.Text = myDataSet.Tables[0].Rows[0]["Zip"].ToString();
                    lblSitOnDate.Text = myDataSet.Tables[0].Rows[0]["Onboarding Date"].ToString();
                    lblSitNotes.Text = myDataSet.Tables[0].Rows[0]["Notes"].ToString();

                    //upGenTaskCli.Update();
                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                }
            }
            if (ddlPra.SelectedIndex > 0)
            {
                try
                {
                    demoPra.Visible = true;
                    query = queryPra + " WHERE P.ATTR2817 = '" + ddlPra.SelectedValue + "'";

                    // create data adapter
                    SqlDataAdapter da = new SqlDataAdapter(query, conn);
                    // this will query your database and return the result to your datatable

                    DataSet myDataSet = new DataSet();
                    da.Fill(myDataSet);
                    lblPra.Text = myDataSet.Tables[0].Rows[0]["Client"].ToString();
                    lblPraRS.Text = myDataSet.Tables[0].Rows[0]["RelatedSite"].ToString();
                    lblPraOnDate.Text = myDataSet.Tables[0].Rows[0]["Onboarding Date"].ToString();
                    lblPraNotes.Text = myDataSet.Tables[0].Rows[0]["Notes"].ToString();

                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                }
            }
            if (ddlPro.SelectedIndex > 0)
            {
                try
                {
                    demoPro.Visible = true;
                    query = queryPro + " WHERE P.ATTR2919 = '" + ddlPro.SelectedValue + "'";

                    // create data adapter
                    SqlDataAdapter da = new SqlDataAdapter(query, conn);
                    // this will query your database and return the result to your datatable

                    DataSet myDataSet = new DataSet();
                    da.Fill(myDataSet);
                    lblPro.Text = myDataSet.Tables[0].Rows[0]["Provider"].ToString();
                    lblProStart.Text = myDataSet.Tables[0].Rows[0]["Start Date"].ToString();
                    lblProRP.Text = myDataSet.Tables[0].Rows[0]["RelatedPractice"].ToString();
                    lblProRC.Text = myDataSet.Tables[0].Rows[0]["RelatedClient"].ToString();

                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                }
            }

            upGenTaskCli.Update();
        }
}

我添加断点这些行:

I added breakpoints for these lines:

lblCli.Text = myDataSet.Tables[0].Rows[0]["Client"].ToString();
lblCliDate.Text = myDataSet.Tables[0].Rows[0]["Onboarding Date"].ToString();
lblCliCont.Text = myDataSet.Tables[0].Rows[0]["Contact Information"].ToString();
lblCliNotes.Text = myDataSet.Tables[0].Rows[0]["Notes"].ToString();

和将鼠标悬停他们,显示文本数据,但 upGenTaskCli 没有更新显示数据。

And hovering the mouse over them, displays the text data but the upGenTaskCli is not updating to show the data.

我收到此错误:

0x800a139e - Microsoft JScript runtime error: Sys.InvalidOperationException: Could not find UpdatePanel with ID 'upGenTaskCli'. If it is being updated dynamically then it must be inside another UpdatePanel.

我如何解决这个问题?

How do I resolve the issue?

推荐答案

自一个JS的可见性的错误,尽量把你的更新面板在另一个更新面板
像这样的:

Since its a JS visibilty error, Try to put your Update Panel inside another update panel like this:

//这是你的看法如何看起来像

//this is how your view should look like

<asp:UpdatePanel ID="pnlParent" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:UpdatePanel ID="upGenTaskCli" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
            <ContentTemplate>
                Client: <asp:Label ID="lblCli" ClientIDMode="Static" runat="server" Text=""></asp:Label>
                <br />
                Onboarding Date: <asp:Label ID="lblCliDate" ClientIDMode="Static" runat="server" Text=""></asp:Label>
                <br />
                Contact Information: <asp:Label ID="lblCliCont" ClientIDMode="Static" runat="server" Text=""></asp:Label>
                <br />
                Notes: <asp:Label ID="lblCliNotes" runat="server" ClientIDMode="Static" Text=""></asp:Label>
                <br />
            </ContentTemplate>
        </asp:UpdatePanel>
</contentTemplate>
</updatePanel>

所以在你的code背后做到以下几点:

so in your code behind do the following :

 protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                ScriptManager.RegisterStartupScript
                       (this, typeof(Page), "UpdateMsg", "$(document).ready(function(){$('#upGenTaskCli').hide();});", true);
            }
        }

//然后在您的按钮逻辑添加以下行的如果子句中:

//and then in your button Logic add the following line in the If clause :

protected void btnFilter_Click(Object sender, EventArgs e)
{
  if (ddlCli.SelectedIndex > 0)
        {
            try
            {

                query = queryCli + " WHERE C.ATTR2815 = '" + ddlCli.SelectedValue + "'";

                // create data adapter
                SqlDataAdapter da = new SqlDataAdapter(query, conn);
                // this will query your database and return the result to your datatable

                DataSet myDataSet = new DataSet();
                da.Fill(myDataSet);
                lblCli.Text = myDataSet.Tables[0].Rows[0]["Client"].ToString();
                lblCliDate.Text = myDataSet.Tables[0].Rows[0]["Onboarding Date"].ToString();
                lblCliCont.Text = myDataSet.Tables[0].Rows[0]["Contact Information"].ToString();
                lblCliNotes.Text = myDataSet.Tables[0].Rows[0]["Notes"].ToString();

            }
            catch (Exception ex)
            {
                string error = ex.Message;
            }
 ScriptManager.RegisterClientScriptBlock
                        (this, typeof(System.Web.UI.Page), "MyJSFunction", "$('#upGenTaskCli').toggle();", true);

}

//它应该工作

//it should work

这篇关于为什么没有在UpdatePanel发现更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆