Asp.net控制回发后不更新 [英] Asp.net controls not updating after a postback
问题描述
我' m编写代码以从asp控件读取数据以更新记录一个数据库。我已经调整了最后一天和我' ve追溯到之前我应该注意到的东西。
代码首先使用数据库中的现有值填充控件。当我单击SAVE时,它应该从控件中读取当前值并保存。不幸的是,实际在做什么是 使用 值 更改前的控件 它们。它' 没有看到对控件的更改。
当我们刷新整个页面控件显示更新的值时,是我们保存数据时的任何方式,并且这些数据在邮件包后反映用户控制。< br $>
aspx页面:
<%@ Page Language =C#AutoEventWireup =trueCodeFile =VerifyFile.aspx.cs Inherits =VerifyFile
Theme =Default%>
<%@ Register TagPrefix =mlmTagName = fileheaderSrc =FileHeader.ascx%>
< body class = lyt_body_class >
< 表格 id = form1 runat = 服务器 >
< mlm:fileheader ID =Header2runat =server/>
< / body>
用户控制Cs文件:
public partial class FileHeader : System 。 Web 。 UI 。 UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Bindcontrol();
}
}
< blockquote>现在问题已解决我使用面板动态加载用户控件
参见代码:
< from>
< asp:Panel ID = plnfileHeader runat = 服务器 >
< / asp:Panel >
verify.aspx page
if (!IsPostBack)
{
控制uc = this.LoadControl(〜/ FileHeader.ascx );;
plnfileHeader.Controls.Add(uc);
}
叫你绑定功能如下 -
page_load-
If(!IsPostBack )
{
在这里调用绑定函数
}
检查你的内容!IsPostBack in您的C#文件并设置您的控件属性AutoPostBack = true!
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" %>
<body class="lyt_body_class">
<form id="form1" runat="server">
<mlm:fileheader ID="Header2" runat="server"/>
</body>
User Control Cs file:
public partial class FileHeader : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Bindcontrol();
}
}
Now issue resolved i used panel for dynamically load that user controls
see the code:
<from>
<asp:Panel ID="plnfileHeader" runat="server"> </asp:Panel>
verify.aspx page
if (!IsPostBack) {
Control uc = this.LoadControl("~/FileHeader.ascx");
plnfileHeader.Controls.Add(uc);
}
Call you binding function like-
on page_load-
If(!IsPostBack)
{
Call here binding function
}
check your contents of the !IsPostBack in your C# file and set your controls property AutoPostBack = true !
这篇关于Asp.net控制回发后不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!