Reputation: 3751
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>
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();
And hovering the mouse over them, displays the text data but the upGenTaskCli
is not updating to show the data.
I receive this error:
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?
Upvotes: 0
Views: 604
Reputation: 3914
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>
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
Upvotes: 2