根据母版页中分配的会话动态创建控件 [英] Create Control Dynamically based on Session Assigned in Master Page

查看:62
本文介绍了根据母版页中分配的会话动态创建控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我在MasterPage中有一个DropDownList,其中保存Years,并根据从MasterPage中选择的值创建会话变量.
在子控件"中,我想基于会话变量创建动态控件,我在子页面中创建了所有必需的控件,但是在保存值时问题仍然存在.

我在子页面中使用了PreRender,它提供了母版页面的准确会话值,但是我的动态控件无法保存其状态(ViewState)
我在子页面中使用了PageLoad,但是在PageLoad中,我从母版页获得了错误的会话值,

请提出任何想法,我应该在子页面中使用哪个事件以具有MasterPage会话的准确值并在子页面中具有动态控件的ViewState?

Dear All, I have a DropDownList in MasterPage which holds Years, and based on the value selected from MasterPage I am creating a session variable.
in Child Control I want to create dynamic controls based on session variables, I created all the required controls in child page but the problem persist while saving the value.

I used PreRender in Child Page which Gives the accurate Session Value from Master Page, but I dynamic control can''t save its state (ViewState)
I used PageLoad in Child Page, but in PageLoad I am getting wrong Session Value from Master Page,

any Ideas please, which event should i use in Child Page to both have the accurate value of MasterPage Session and have ViewState of Dynamic Control in Child Page?

推荐答案

"不要动态创建控件,并且如果您在Page Load或更高版本中创建控件,请不要期望它们具有状态.网上有大量的文章.我发现最简单的方法是拥有一个隐藏的控件,然后使用javascript来存储我动态创建的控件的值,或者如果我的动态控件的范围受到限制(即,没有无限多个文本框)例如),可以一直创建它们,并根据需要隐藏/显示它们.
You can''t create controls dynamically and expect them to have state if you create them during Page Load or later. There''s tons of articles on this on the web. I find the easiest thing to do, is have a hidden control, and in that use javascript to store the values of my dynamically created controls, or if my dynamic controls are limited in scope ( i.e. there''s not an infinite number of textboxes possible, for example ), just create them all the time and just hide/show them as needed.


这篇关于根据母版页中分配的会话动态创建控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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