开发者

ViewState - how to persist state between two pages

On page1.aspx i hava a textbox with id="tb1" On page2.aspx I have a textbox with id="tb2"

page2.aspx is set as postbackurl for page1.aspx. For both labels enabl;eViewState is true. Shouldn't the text I write in page1 also appear in the label on page2? Can I implement th开发者_StackOverflow中文版is without looking into Request headers, and setting the text myself?


ViewState is a blob of Javascript that is persisted for a single page, not across multiple. When you use the PostBackUrl property to post to a different page than the initial page, you need to perform your own validation, and pull property values from the controls on the "previous page":

// Get the value of TextBox1 from the page that 
// posted to this page.
text = ((TextBox)PreviousPage.FindControl("tb1")).Text;

Also, ViewState is honored on a per-control basis so even if what you wanted to happen was possible, the fact that your TextBoxes have two different IDs would mean ViewState wouldn't be able to match them up...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜