Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I'm writing code to read data from asp controls to update records in a database. I've been debugging the last day and I've tracked it back to something that I ought to have noticed before.

The code first populates the controls with the existing values from the database. When I click SAVE, it should read the current values from the controls and save with those. Unfortunately, what it's actually doing is using the values of the controls before a change was made to them. It's not seeing the change to the controls.



when we refresh whole page control show updated values, is that any way when we save data and that data reflect with user control after post pack.

aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VerifyFile.aspx.cs" Inherits="VerifyFile"
Theme="Default" %>

<%@ Register TagPrefix="mlm" TagName="fileheader" Src="FileHeader.ascx" %>

XML
<body class="lyt_body_class">
    <form id="form1" runat="server">


<mlm:fileheader ID="Header2" runat="server"/>

</body>

User Control Cs file:

CSS
public partial class FileHeader : System.Web.UI.UserControl
{
    

    protected void Page_Load(object sender, EventArgs e)
    {

    Bindcontrol();

    }
}
Posted
Updated 21-Oct-14 19:51pm
v2
Comments
[no name] 22-Oct-14 1:26am    
Check that you should be binding the controls under the condition if(!Page.IsPostBack) in the OnLoad event.
DamithSL 22-Oct-14 1:33am    
need more information, can you update question with sample code related to this issue?
Kamar Shahzad 22-Oct-14 1:39am    
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VerifyFile.aspx.cs" Inherits="VerifyFile"
Theme="Default" %>
Please have a look ,control is calling in a .aspx page and control bind fileheader.ascx.cs file (that is the problem)

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<%@ Register TagPrefix="mlm" TagName="fileheader" Src="FileHeader.ascx" %>


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

Now issue resolved i used panel for dynamically load that user controls

see the code:

<from>
XML
<asp:Panel ID="plnfileHeader" runat="server">
</asp:Panel>





verify.aspx page

SQL
if (!IsPostBack)
        {

Control uc = this.LoadControl("~/FileHeader.ascx");

plnfileHeader.Controls.Add(uc);
}
 
Share this answer
 
Call you binding function like-


on page_load-

If(!IsPostBack)
{
Call here binding function
}
 
Share this answer
 
check your contents of the !IsPostBack in your C# file and set your controls property AutoPostBack = true !
 
Share this answer
 
Comments
Kamar Shahzad 22-Oct-14 2:18am    
view this please also checking post back
if (!IsPostBack)
{
BindControl();
}
else
{
BindControl();
}
Member 11148158 22-Oct-14 2:28am    
try setting the autopostback property to true for the control you are binding the data with

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900