表单提交和刷新 [英] Form Submission and Refresh

查看:86
本文介绍了表单提交和刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


因为我错过了一些关于ASP.NET,

或者我所做的事情,我自己也疯了我试图做的事情根本无法完成。


首先,我没有使用会话变量来跟踪状态。我的应用程序将最终进行网络养殖,因此我拒绝使用任何会话变量。


其次,我想要做的很容易。我试图阻止的似乎是不可能的。


我有网络表格a和网络形式b。 a.aspx包含一个表单; b.aspx显示a / b $ b提交的数据。我正在使用Context对象在Server.Transfer(b.aspx)操作之后从a.aspx向b.aspx提供信息



工作,没问题。


问题是,如果用户点击< F5>在IE浏览器中(刷新),当他们查看b.aspx时,则重新显示a.aspx,并且重复显示重复行。错误

消息显示,因为a.aspx将一个唯一的行插入数据库

表。


我正在尝试"检测"当用户刷新文档b.aspx时。


我明白如果我使用a.aspx中的Response.Redirect转到b.aspx,

那么这个问题不会发生。但后来我遇到了一个新问题:我如何使用b.aspx将数据提交给a.aspx而不使用会话

变量或查询字符串变量?由于我之前提到的原因,会话变量不可能

; querystring变量将是凌乱的,

因为在a.aspx中输入了十几个字段...


我唯一能想到的是使用Response.Redirect(" b.aspx"),

只传递记录密钥信息。然后我可以从数据库中读取提交的数据

。但这似乎很愚蠢,因为用户刚刚提交了

数据。在这些

的情况下,采用数据库命中似乎很浪费。


除非我遗漏了一些大的东西,否则似乎没有好的方法可以使用

Context和Server.Transfer() - 并且还检测刷新,以便表单是

不重新显示,而是摘要(b.aspx)页面可能是显示

代替。


任何想法都会非常感激。


非常感谢你,

Jim

Hello,

I''m driving myself crazy either because I''m missing something about ASP.NET,
or what I''m trying to do simply can''t be done.

First, I am not using session variables to track state. My app will
ultimately be web-farmed, so I resisted using either session variables.

Second, what I''m trying to do is easy. What I''m trying to prevent seems
impossible.

I have web form "a" and web form "b". a.aspx contains a form; b.aspx shows
the data submitted by a. I am using the Context object to make information
from a.aspx available to b.aspx after a Server.Transfer("b.aspx") operation.
This works, no problem.

The problem is that if the user hits <F5> (refresh) in IE while they''re
viewing b.aspx, then a.aspx is re-displayed and a "duplicate row" error
message is displayed, since a.aspx inserts a unique row into a database
table.

I am trying to "detect" when a user refreshes document b.aspx.

I understand that if I used Response.Redirect from a.aspx to go to b.aspx,
then this problem wouldn''t occur. But then I have a new problem: how do I
make data submitted to a.aspx available in b.aspx without using session
variable or querystring variables? The session variables are not possible
for the reason I mentioned earlier; querystring variables will be messy,
because there are a dozen or so fields entered in a.aspx...

The only thing I could think of is to use Response.Redirect("b.aspx"), and
pass only the record-key information. I could then read the submitted data
from the database. But that seems silly, since the user just submitted the
data a moment before. Taking a database hit seems wasteful under these
circumstances.

Unless I''m missing something big, it seems that there is no good way to use
Context and Server.Transfer()--and also detect a refresh so that the form is
NOT redisplayed but, rather, the summary (b.aspx) page could be displayed
instead.

Any ideas would be greatly appreciated.

Thank you so much,
Jim

推荐答案

Jim,

只是想一想,不知道你是否有能力设置viewstate = true

....

你能使用一对面板a和b吗?在一个页面上a.aspx。

面板a保存数据输入字段,默认情况下可见,面板b

保存摘要字段,默认情况下隐藏。 br />
在数据库插入结束时,切换面板可见性等




视图状态应该表示面板b应该

F5之后仍然可见,没有任何附加行插入。


Shaun

Jim,
Just a thought, don''t know if you have capability to set viewstate=true
....
Can you use a pair of panels a and b. on a single page a.aspx.
Panel a holds the data entry fields and is visible by default, panel b
holds the summary fields and is hidden by default.
At the end of your database insert, switch the panel visiblities etc
etc.

The viewstate should mean that panel b should remain visible after an
F5 without any addition row insert.

Shaun


嗨Shaun:


不,我试过了。事实上,我首先使用面板作为我的解决方案,直到我发现刷新问题为止。如果你点击< F5>当面板b显示并且面板a被隐藏时,状态是状态。整个表格恢复到原来的状态。\\ b $ b状态。这意味着面板a'的可见性为真,面板b'为假。


我用按钮和两个面板创建了一个简单的测试。当第一次运行页面

时,我显示panel1(a)。当您单击按钮时,我显示panel2

(b)。如果你然后点击< F5> (刷新)并查看Panel1.Visible的值,

这是真的,而不是假的。


还有其他任何想法吗?


谢谢,

- Jim


private void Page_Load(object sender,System.EventArgs e)


{


//将用户代码置于此处初始化页面


if(!this.IsPostBack)


{


this.Panel1.Visible = true;


this.Panel2.Visible = false;


}


}


#region Web表单设计器生成的代码


覆盖protected void OnInit(EventArgs e)


{


//


// CODEGEN:ASP.NET Web窗体设计器需要此调用。


//


base .OnInit(e);


InitializeComponent();


}

///< summary>


/// Designer支持所需的方法 - 不要修改


///使用代码编辑器的方法内容。


///< / summary>


private void InitializeComponent()

{


this.Button1.Click + = new System.EventHandler(this.Button1_Click);


this.Load + = new System.EventHandler(this.Page_Load);


}


#endregion


private void Button1_Click(object sender,System.EventArgs e)


{


this.Panel1.Visible = false;


this.Panel2.Visible = true;


}


}
Hi Shaun:

No, I tried that. In fact, I had first used panels as my solution until I
discovered the refresh problem. If you hit <F5> when panel b is showing and
panel a is hidden, the "state" of the entire form is back to its original
state. That means that panel a''s visibility is true and panel b''s is false.

I created a simple test for with a button and two panels. When the page
first runs, I display panel1 (a). When you click the button, I show panel2
(b). If you then hit <F5> (refresh) and look at the value of Panel1.Visible,
it will be true, not false.

Any other ideas?

Thank you,
-- Jim

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

if (!this.IsPostBack)

{

this.Panel1.Visible = true;

this.Panel2.Visible = false;

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

base.OnInit(e);

InitializeComponent();

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void Button1_Click(object sender, System.EventArgs e)

{

this.Panel1.Visible = false;

this.Panel2.Visible = true;

}

}


Jim,


我的大脑花了一段时间才进入C模式但是......


我注意到你正在页面加载中切换面板visibilites。

我一直使用它并且面板可见默认设置为

标签级别

例如< asp:panel id =" a" RUNAT = QUOT;服务器"可见= QUOT;真">和< asp:panel

id =" b" RUNAT = QUOT;服务器" visible =" false">


然后我确保在页面

加载期间不会切换visibilites,仅响应按钮点击。

Shaun

Jim,

It took my brain a while to get into C mode but ..

I notice that you are switching the panel visibilites in the page load.
I use this all the time and have the panel visibilty defaults set at
tag level
eg <asp:panel id="a" runat="server" visible="true"> and <asp:panel
id="b" runat="server" visible="false">

Then I make sure that the visibilites are not switched during page
load, only in response to a button click.
Shaun


这篇关于表单提交和刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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