?
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
?
666 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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