English 中文(简体)
文本箱不更新
原标题:Textbox not updating on page load ASP.net

我的网页上有一个充满活力的桌子,其中包含有用户可以改变的违约文本箱。 用户投入值也有一些验证(例如,投入不得少于零)。 当用户提交表格时,只储存了有效的投入,而该网页正在更新,将储存的数值填入重新设计的表格。 出于某种原因,文本箱在提交和重载该页之后仍然会显示无效投入,尽管这些投入并非持久性,但这一问题不会出现在标签上。

是否在案文箱控制中专门纳入了造成这一问题的内容? 是否有任何地方储存国家,或许(我试图制定<条码> 意见国 国旗以伪造)? 这是否只是网页生命周期的一部分?

文本框以“Load事件”页呼吁的方法建造。

void Page_Load(object sender, EventArgs e)
{
//page initialization...
ValidateData(); //This is where the current data is verified, and stored if valid
BuildTable(); //This takes that stored value for the text
}

void BuildTable
{ 
tbTable = new Table();  
tbRow = new TableRow();
tbCell = new TableCell();
TextBox tb = new TextBox();
tb.text = some stored value;
tbCell.Controls.Add(tb);
tbRow.Cells.Add(tbCell);
tbTable.Rows.Add(tbRow);
divFromPage.Controls.add(tbTable);
}

如果需要更多信息帮助解决这一问题,我就知道。

最佳回答

仅以Doh时段为例,我刚刚把数据列入两性问题会前活动,而且由于所有投入,数据只是细微的。

问题回答

Edit : After reproducing your problem i came to the following conclusion.
I believe the problem is not the viewstate but asp is just repopulating these values because the form data which you submited has the same name as the input element which you are returning.
Even though you generate them dynamicly since you add them to the same div the result is always the same. This leads me to 2 solutions :) :
My solution nr 3 still stands , i tried it out and on button click redirecting works as intended with no posted data creeping back into my textbox.
This statement takes care of that :

Response.Redirect("~/test.aspx");

Alternativly you could generate a random ID to make sure the inputfields names you are returning are different from the ones that were submited. You wouldn t have to change all the names but if the table ID for example is different the entire table won t get populated with the submitted data anymore.

Be aware that you might need a if(IsPostBack) in your pageload because your data will be lost right after pageload(unless you handle the saving before that)


If you are doing a postback asp.net uses it s viewstate to maintain all the textbox,textfields and all other form elements(including input type hidden).
I currently see 3 solutions to your problem :
You could do what ivowiblo suggested, before you load the data from the database( i assume you do) you could wipe all the textfields. On a first time visit this will be pointless off course since they are blank. But after a postback it will actually wipe the textfields.

You could disable the viewstate on those textboxes so asp will not persist the state. I m not sure why your test didn t work but it should work. If you choose this approach feel free to edit your question with some actual code

My personal favorite : Redirect the page. In stead of just returning the result and causing a postback to the page do the following : after the user hits the save button you can save the data and then do a Response.Redirect to your current page. The browser will be redirected to the page and no viewstate will be involved.




相关问题
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!

热门标签