简单的 ASP.NET 问题

发布于 2024-10-06 01:18:32 字数 331 浏览 0 评论 0原文

我有两个网络表单。示例:a.aspx 和 b.aspx

在 a.aspx 中,我有一个带有 ID="Textbox1" 的文本框。 在 b.aspx 中,我有一个带有 ID="Label1" 的标签

,当我打开 b.aspx 时,Label1.text = Textbox1.Text..

但是当我在b.aspx Page_Load函数中编写时,智能感知不知道Textbox1

我怎样才能做到这一点?

I have two web form. example: a.aspx and b.aspx

In a.aspx i have a textbox with ID="Textbox1".
In b.aspx, i have a label with ID="Label1"

I want when i open b.aspx, Label1.text = Textbox1.Text..

but when i write in b.aspx Page_Load function, intellisense doesn't know Textbox1.

How can i do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

挽袖吟 2024-10-13 01:18:33

当用户请求 .aspx 时,ASP.NET 会创建 Page 类(Web 表单)的新实例,对其进行处理,然后将生成的 HTML 发送给用户。最后它销毁了页面实例。

当您单击 ASP.NET 页面上的按钮时,您将“回发”到同一 URL(即从 a.aspx 返回 a.aspx)。接下来,ASP.NET 执行一些魔法:它将用户输入到表单元素中的值映射到页面上的控件,例如 Textbox1

要跨页面共享值,您需要使用以下机制之一:

  • 直接发布到页面b。有关执行此操作的惯用 ASP.NET 方法,请参阅跨页 在 ASP 中发帖。 NET 网页

  • 将数据包含在URL 本身中,例如,通过使用查询字符串:

    http://www.mysite.com/b.aspx?contents=foo

  • 将数据保存在a 会话变量(或 cookie)。这不是一个好主意,除非该值确实限定在用户会话范围内(例如,设置时区)。此外,如果可扩展性很重要,则需要更加小心会话。

  • 将数据保存在数据库中,然后在构建其他页面时检索它。

When a user requests an .aspx, ASP.NET creates a new instance of your Page class (the web form), processes it, then sends the resulting HTML to the user. Finally it destroys the page instance.

When you click a button on an ASP.NET page, you "post back" to the same URL (that is, you go from a.aspx back to a.aspx). Next, ASP.NET performs some magic: it maps values that users entered into form elements to controls on your page like Textbox1.

To share values across pages, you need to use one of the following mechanisms:

  • Post directly to page b. For the idiomatic ASP.NET way of doing this, see Cross-Page Posting in ASP.NET Web Pages.

  • Include the data in the URL itself, for example, by using a querystring:

    http://www.mysite.com/b.aspx?contents=foo

  • Save the data in a session variable (or a cookie). This isn't a good idea unless the value is really scoped to the user's session (e.g., setting a time zone). Additionally, if scalability is important, you need to take greater care with session.

  • Save the data in a database, then retrieve it when building other pages.

转身以后 2024-10-13 01:18:33

您很可能执行了某些操作,例如单击 a.aspx 上的按钮会将您带到 b.aspx,对吧?在该按钮单击的函数中,您可以将文本框的内容添加到查询字符串并重定向到 b.aspx。

response.redirect("b.aspx?contents=" + Textbox1.text);

然后在 b.aspx 中的 page_load 中,您会执行以下操作:

Label1.text = request("contents");

这就是您要问的吗?如果您在智能感知中没有看到它,您可能只需要关闭并重新打开页面,以便它与设计器文件同步。

most likely you have some action, like a button click on a.aspx that takes you to b.aspx, right? In the function for that button click, you would add the contents of the textbox to the querystring and redirect to b.aspx.

response.redirect("b.aspx?contents=" + Textbox1.text);

and then in b.aspx, in page_load, you would do:

Label1.text = request("contents");

Is that what you're asking? If you don't see it in intellisense, you might just need to close and reopen the page so that it will sync with the designer file.

花桑 2024-10-13 01:18:33

它可以通过多种方式完成。
这里我告诉大家两个简单易行的方法
1. 您可以将值作为 url 中的参数发送
如果您通过单击按钮、链接按钮等访问 b.aspx。您可以像这样添加它

 Response.Redirect("b.aspx?val="+text1.Text);

U can able to get the value by using 
String txt=Request.QueryString["val"];
  1. 您可以使用会话变量。因此,如果您使用会话变量,则可以从您网站{aspx 中的任何页面访问该值}.

    Session["val"]=textBox1.Text; //第一页
    Label1.Text=Session["val"].ToString();//第2页

希望你尝试这个

It can be done in many ways.
Here i am telling two simple and easy methods
1. U can send the values as a parameter in the url
if u r going to b.aspx by click a button,link button etc. U can add it like this

 Response.Redirect("b.aspx?val="+text1.Text);

U can able to get the value by using 
String txt=Request.QueryString["val"];
  1. You can use session variables.So if u r using session variables the value can be acessed from any page in ur website{aspx}.

    Session["val"]=textBox1.Text; //1st page
    Label1.Text=Session["val"].ToString();//2nd page

Hope u try this one

十二 2024-10-13 01:18:33

将值保存在会话中。这样用户可以输入大量文本,并且不会使 URL 看起来很难看。 URL 允许的长度也有限制。

使用如下 C# 代码:

// create a new Session variable to store the users name
Session ( 'SomeText' ) = 'James';

// display the name in any page on your site
Out ( 'Your value is ' + Session ( 'SomeText' ) ); 

save the value in session. this way users can type large amounts of text and it wont make the URL look ugly. also there is a limit to the length allowed for a URL.

use c# code such as this:

// create a new Session variable to store the users name
Session ( 'SomeText' ) = 'James';

// display the name in any page on your site
Out ( 'Your value is ' + Session ( 'SomeText' ) ); 
画离情绘悲伤 2024-10-13 01:18:33

您始终可以使用母版页,并在母版页上公开公共属性。将此属性写入页面的视图状态,由于它是公共的,因此 pageA 可以写入该值,而 pageB 可以读取该值。

You can always use Masterpages, and expose a public property on the masterpage. Have this property write to the viewstate of the page, and since it's public, pageA can write the value, and pageB can read the value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文