Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Viewstate is not maintained for the inner controls if i used Enabled/disabled property in my server control

Posted on 2007-11-27
2
Medium Priority
?
669 Views
Last Modified: 2013-12-16
Gurus,

I am developing a server control which is used as a custom tag in asp.net pages. Basically this server control will be acting as a container (but not actuallly) control to render other controls within this. For ex. If the logged in user has appropriate rights, this server control allows the child controls to render as visible or enabled based on the logged in user rights.

i have written a logic in this server control's Render event procedure. here is the sample code snippet

if(!isuserinrole())
{
foreach (Control ctl in this.Controls)
                {
                    ctl.EnableViewState = true;
                    DisableControl(ctl);
                  ctl.RenderControl(writer);                    
                }
}
private void DisableControl(Control control)
        {
            if (control is WebControl)
            {
                ((WebControl)control).EnableViewState = true; //((WebControl)control).Enabled = false;
                ((WebControl)control).Attributes.Add("disabled", "disabled");
            }
            else if (control is HtmlControl)
                ((HtmlControl)control).Attributes.Add("Disabled", "True");
        }

this is working fine for first time. if i do postback and come back to the page, i am loosing all data in textboxes. what is the problem? am i missing anything in viewstate maintanance? please advise me. Thanks for your help.

Ram.
if(!isuserinrole())
{
foreach (Control ctl in this.Controls)
                {
                    ctl.EnableViewState = true;
                    DisableControl(ctl);
                  ctl.RenderControl(writer);                    
                }
}
private void DisableControl(Control control)
        {
            if (control is WebControl)
            {
                ((WebControl)control).EnableViewState = true; //((WebControl)control).Enabled = false;
                ((WebControl)control).Attributes.Add("disabled", "disabled");
            }
            else if (control is HtmlControl)
                ((HtmlControl)control).Attributes.Add("Disabled", "True");
        }

Open in new window

0
Comment
Question by:rampravee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:rampravee
ID: 20399204
I found the solution for this. Instead of checking this logic in Render method, i checked it in oninit event procedure to achieve the same.

it works fine.  it may be helpful for other users when they really need this functionality.
0
 

Accepted Solution

by:
EE_AutoDeleter earned 0 total points
ID: 20968370
Cruthin,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question