跨页投递

编程入门 行业动态 更新时间:2024-10-28 00:21:33
本文介绍了跨页投递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只是想跨页投递的例子。 我已经添加1文本框和放大器; 1按钮Default.aspx页

i am just trying the example of cross page posting. i have added 1 textbox & 1 button to default.aspx page

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button2" runat="server" Text="Button" PostBackUrl="~/About.aspx"/>

我增加了以下code至code-背后about.aspx页的文件

i have added following code to code-behind file of about.aspx page

protected void Page_Load(object sender, EventArgs e) { if (Page.PreviousPage != null) { TextBox SourceTextBox = (TextBox)Page.PreviousPage.FindControl("TextBox1"); if (SourceTextBox != null) { Label1.Text = SourceTextBox.Text; } else Label1.Text = "no value"; } else Label1.Text = "no value from previous page"; }

当我进入TextBox1中与放一些文字;点击按钮,它进入about.aspx但标签显示值没有价值,它没有显示TextBox1中的文本值,这是为什么不正常?

when i enters some text in textbox1 & clicks button, it goes to about.aspx but label shows value "no value", its not showing textbox1's text value, why this is not working properly?

推荐答案

如果您有母版页则code 页previousPage.FindControl(TextBox1的); 无法工作,因为 TextBox1的是的ContentPlaceHolder。,必须先找到的ContentPlaceHolder。,然后找到 TextBox1的

If you have master page then the code Page.PreviousPage.FindControl("TextBox1"); not work because the TextBox1 is under the ContentPlaceHolder. and must first locate the ContentPlaceHolder. and then find the TextBox1

但是有得到的值的最简单的方法如下:

But there is an easiest way to get the value as:

将这个previous页:

Place this on the previous page:

public string TextFromBox1 { get { return TextBox1.Text; } }

和重定向页面上声明什么是对的aspx为previous页:

and on the redirect page declare what is the previous page on aspx as:

<%@ Reference Page ="~/PreviousPageName.aspx" %>

和code背后获得的价值为:

and on code behind get the value as:

if (Page.PreviousPage != null) { if (Page.PreviousPage is PreviousPageClassName) { Label1.Text = ((PreviousPageClassName)Page.PreviousPage).TextFromBox1; } else { Label1.Text = "no value"; } } else Label1.Text = "no value from previous page";

更多推荐

跨页投递

本文发布于:2023-10-12 02:37:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483522.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!