English 中文(简体)
离职后问题
原标题:Post back issue
  • 时间:2010-06-19 11:50:38
  •  标签:
  • c#
  • asp.net

OK. Let me ask the question this way: Generically, isn t the page cycle:

页: 1

浮标和(或)提交处理器

页: 1.

If so, what should the values of the controls on the page be during the onclick/submit handlers? The values selected by the users, or the values from 页: 1?

问题回答

页面负荷活动在<>之前发射控制活动。 因此,如果你改变页面负荷活动的价值,那么这些变化将超出用户选择的任何价值,在控制活动中,你将看到你在页面负荷上设定的价值。

如果你需要在页面负荷活动上做一些初步工作,但只有当有人第一次上页时,你才能使用IsPostBack:

if(!IsPostBack)
{
  //do initialization that you only want to happen when someone
  //comes to the page for the first time
}

http://msdn.microsoft.com/en-us/library/ms178472.aspx” rel=“nofollow noreferer”>overview of the ASP。 互联网网页寿命,详情很多。

下面是简化的例子顺序:

  1. Browser requests the page
  2. Page Load fires
  3. Page renders and is sent to the browser
  4. User does something on the page (clicks a button, changes a text box that is set to autopostback, etc)
  5. Browser does a POST to the page
  6. Page Load fires (again). This time IsPostBack is True. Also note, this is not the same "Page" object as it was in #2. Each HTTP request is a completely new Page object. For example, member variables will not be saved across requests.
  7. Appropriate control events fire (click, text changed, etc)
  8. Page renders and is sent back to the browser again

这取决于你是否检查该页的背后。

考虑以下例子:一个系统的用户有机会在网上更改其名称。 当页数时,用户名称放在正文箱上。 用户然后可以点击一个吨,以拯救其名称。

举例来说,让人们假设,一个名为“John Smith”的用户名被错误地储存为“John Jones”。 然后,他决定在用户名领域打上“John Smith”的打字,改变他的用户名。

protected void Page_Load(object sender, EventArgs e)
{
this.txtName.Text = "John Jones";
}

protected void SaveDetails(object sender, EventArgs e)
{
string username = this.txtName.Text;
}

In this case, you would expect that the string username would now be set to "John Smith." However, as the page loads again on a postback, it actually resets to "John Jones".

因此,我们必须检查一下该页是否是倒退。

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostback)
    {
    this.txtName.Text = "John Jones";
    }
}

现在,用户名示意图将定在“约翰·史密斯”。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签