如何从ASP.NET中的上一页获取控件(主页面配置) [英] How to get controls from previous page in ASP.NET (Master page configuration)

查看:68
本文介绍了如何从ASP.NET中的上一页获取控件(主页面配置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello all



在我的asp.net应用程序中,我为所有页面使用一个母版页。在某些页面中,我想从上一页获得一个控件并从中获取一个值,我用它做了这个:



Hello all

In my asp.net application I use one master page for all pages. In some page I want to get a control from the previous page and get a value from it, I did it using this:

rblOperation.SelectedIndex = ((RadioButtonList)Page.PreviousPage.FindControl("rblOperation")).SelectedIndex;





rblOperation是所有页面中都存在的单选按钮列表。无论我想做什么,前面的语句都会抛出NullReferenceException。这是正确的方法吗?



rblOperation is a radio button list exists in all pages. Regardless of what I want to do, the previous statement throws NullReferenceException. Is this the right way to do it ?

推荐答案

您应该将选择存储在会话变量或URL中,而不是从上一页访问控件。新页面。



此外,你不应该在没有检查它的存在和有效性的情况下使用该对象:

Instead of accessing the control from previous page you should store the selection in session variable or URL and read it again on the new page.

Also, you should never use the object without checking for its existence and validity:
RadioButtonList rblOperation = (RadioButtonList)Page.PreviousPage.FindControl("rblOperation")
if (rblOperation != null)
{
// continue working
else
// handle not found condition
}


这篇关于如何从ASP.NET中的上一页获取控件(主页面配置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆