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
665 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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