Asp.net控制回发后不更新 [英] Asp.net controls not updating after a postback

查看:76
本文介绍了Asp.net控制回发后不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'  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屋!

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