为什么没有在UpdatePanel发现更新数据

编程入门 行业动态 更新时间:2024-10-27 09:42:34
本文介绍了为什么没有在UpdatePanel发现更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have the following code in my ASP 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发现更新数据

本文发布于:2023-11-25 00:19:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627526.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发现   数据   UpdatePanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!