简体   繁体   English

在其他页面中找到控件

[英]To find Control in Other page

I'm creating a web application using C#.net My webpage contains a Hidden Field Control. 我正在使用C#.net创建一个Web应用程序。我的网页包含一个“隐藏字段控件”。 I need to use this control's value in another page. 我需要在另一页中使用此控件的值。 I declared a method and inside this method i passed the entire page as a parameter. 我声明了一个方法,并在此方法内部将整个页面作为参数传递。 In another classfile i defined this method. 在另一个类文件中,我定义了此方法。 Inside the method i tried to access the Controls that was in the page created. 在方法内部,我尝试访问所创建页面中的控件。 I tried but i can't get the control. 我试过了,但我无法控制。

Code: 码:

HiddenField hdnTotal = page.FindControl("hdnTotal") as HiddenField;

Is anyother option to find this control in other class file. 是在其他类文件中找到此控件的任何其他选项。

Thanks In Advance! 提前致谢!

Instead of passing a page as parameter did you try using PreviousPage property to find a control? 您没有使用页面作为参数,而是尝试使用PreviousPage属性来查找控件? On the page where you want the control from previous page you could find hidden file like this: 在需要上一页控件的页面上,您可以找到这样的隐藏文件:

HiddenField hf = (HiddenField)PreviousPage.FindControl("hdnTotal");

The normal way to get data from one page to another is to POST the first page to the second page in hidden/form fields. 从一页到另一页获取数据的通常方法是在隐藏/表单字段中将第一页发布到第二页。

Is there a reason you're trying to pass the entire control instead of having the control (for example) just set the value of one or more hidden form fields? 您是否有理由尝试传递整个控件,而不是让控件(例如)仅设置一个或多个隐藏表单字段的值?

You have several options: to use cross-page posting or to pass the value of that hidden field as a GET parameter to another page when redirecting. 您有几种选择:使用跨页发布或在重定向时将隐藏字段的值作为GET参数传递给另一个页面。 Also you can save the value in session or in cookie and access it later. 您也可以将值保存在会话或cookie中,以后再访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM