Professional Web Applications Themes

Viewstate of WebUserControl does NOT work - ASP

Hi, Viewstate of WebUserControl does NOT work although the 'EnableViewstate'-property of the usercontrol is set to true Description : Using ASP.Net : I have a created a WebPage with 2 buttons and 1 Web-UserControl of type LottoWebUserControl. The control has 1 label-control embedded The purpose is to toggle the visible-property of the embedded-label-ctrl using the 2 buttons: Some sample code : public class LottoWebUserControl : System.Web.UI.UserControl { private void Page_Load(object sender, System.EventArgs e) { if ( ! IsPostBack ) MyVisible = false; else MyVisbile = (bool)ViewState["visible"]; } public bool MyVisible { get { return (bool)ViewState["visible"]; } set { ViewState["visible"] = ...

  1. #1

    Default Viewstate of WebUserControl does NOT work

    Hi,

    Viewstate of WebUserControl does NOT work although the
    'EnableViewstate'-property of the usercontrol is set to true

    Description :

    Using ASP.Net :
    I have a created a WebPage with 2 buttons and 1 Web-UserControl of type
    LottoWebUserControl. The control has 1 label-control embedded

    The purpose is to toggle the visible-property of the embedded-label-ctrl
    using the 2 buttons:

    Some sample code :

    public class LottoWebUserControl : System.Web.UI.UserControl
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    if ( ! IsPostBack )
    MyVisible = false;
    else
    MyVisbile = (bool)ViewState["visible"];
    }
    public bool MyVisible
    {
    get { return (bool)ViewState["visible"]; }
    set
    {
    ViewState["visible"] = value;
    SetState();
    }
    }
    private void SetState()
    {
    lbl1.Visible = (bool)ViewState["visible"];
    }
    }

    // The Web-Page containing the 2 buttons and an instance of the usercontrol
    // 'EnableViewstate'-property of the usercontrol is set to true
    public class WebForm1 : System.Web.UI.Page
    {
    protected LottoWebUserControl m_LottoWebUserControl = new
    LottoWebUserControl();

    private void button1_Click(object sender, System.EventArgs e)
    {
    m_LottoWebUserControl.MyVisible = true;
    }
    private void button2_Click(object sender, System.EventArgs e)
    {
    m_LottoWebUserControl.MyVisible = false;
    }
    }

    The toggling does NOT work. The label-ctrl remains in one state.

    Maybe a clue : ViewState["visible"] has a correct value when used in the
    Page_Load() handler but when accessed in the set-part of MyVisible-property
    has it a value of null (before ViewState["visible"] = value; is executed)

    any ideas ?
    thanks

    Chris



    Christian Guest

  2. #2

    Default Re: Viewstate of WebUserControl does NOT work

    Christian wrote on 15 jul 2003 in microsoft.public.inetserver.asp.general:
    > Viewstate of WebUserControl does NOT work although the
    > 'EnableViewstate'-property of the usercontrol is set to true
    this is a classical ASP ng !

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  3. #3

    Default Re: Viewstate of WebUserControl does NOT work

    Evertjan wrote : "this is a classical ASP ng ! "

    ok, but then again.


    "Evertjan." <exjxw.hannivoortinterxnl.net> wrote in message
    news:Xns93B967F70CAEFeejj99194.109.133.29...
    > Christian wrote on 15 jul 2003 in microsoft.public.inetserver.asp.general:
    >
    > > Viewstate of WebUserControl does NOT work although the
    > > 'EnableViewstate'-property of the usercontrol is set to true
    >
    > this is a classical ASP ng !
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)

    Christian Guest

  4. #4

    Default Re: Viewstate of WebUserControl does NOT work

    Christian wrote on 15 jul 2003 in
    microsoft.public.inetserver.asp.general:
    > "Evertjan." <exjxw.hannivoortinterxnl.net> wrote in message
    > news:Xns93B967F70CAEFeejj99194.109.133.29...
    >> Christian wrote on 15 jul 2003 in
    >> microsoft.public.inetserver.asp.general:
    >>
    >> > Viewstate of WebUserControl does NOT work although the
    >> > 'EnableViewstate'-property of the usercontrol is set to true
    >>
    >> this is a classical ASP ng !
    >
    > ok, but then again.
    If you wish:

    "this is a classical ASP ng !"

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  5. #5

    Default Re: Viewstate of WebUserControl does NOT work

    Christian wrote:
    > Evertjan wrote : "this is a classical ASP ng ! "
    >
    > ok, but then again.
    >
    OK, how about this?

    This is a classic asp newsgroup. While you may be lucky enough to find a
    dotnet-savvy person here who can answer your question, you can eliminate the
    luck factor by posting your question to an appropriate group. I suggest
    microsoft.public.dotnet.framework.aspnet.

    HTH,
    Bob Barrows


    Bob Barrows Guest

  6. #6

    Default Re: Viewstate of WebUserControl does NOT work

    Yeah, and stop making us feel bad. The poor us, who are stuck with "classic"
    ASP :(

    :)


    "Bob Barrows" <reb_01501> wrote in message
    news:ulPEGxsSDHA.2148TK2MSFTNGP10.phx.gbl...
    > Christian wrote:
    > > Evertjan wrote : "this is a classical ASP ng ! "
    > >
    > > ok, but then again.
    > >
    > OK, how about this?
    >
    > This is a classic asp newsgroup. While you may be lucky enough to find a
    > dotnet-savvy person here who can answer your question, you can eliminate
    the
    > luck factor by posting your question to an appropriate group. I suggest
    > microsoft.public.dotnet.framework.aspnet.
    >
    > HTH,
    > Bob Barrows
    >
    >

    Michael Guest

Similar Threads

  1. Failed to load viewstate. The control tree into which viewstate...
    By Josema in forum ASP.NET Building Controls
    Replies: 5
    Last Post: April 13th, 07:48 AM
  2. ViewState properties and mapped properties don't work well togethe
    By Christophe Peillet in forum ASP.NET Building Controls
    Replies: 2
    Last Post: January 21st, 07:35 PM
  3. flash programming from WebUserControl
    By Dave Johnson in forum ASP.NET Building Controls
    Replies: 0
    Last Post: January 14th, 06:05 AM
  4. Viewstate errors... how do I get viewstate working?
    By mark in forum ASP.NET Building Controls
    Replies: 0
    Last Post: February 20th, 02:17 PM
  5. Viewstate of WebUserControl does NOT work
    By Christian in forum ASP.NET General
    Replies: 2
    Last Post: July 15th, 03:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139