Dynamic LinkButton, ViewState

Discussion in 'ASP .Net' started by Andrew Robinson, Jun 16, 2006.

  1. I have a <asp:table> control with a large number of dynamically created
    LinkButtons. I am using the command event, command name and command argument
    values in my LinkButtons to trigger actions after the post back. The table
    is dynamically generated based on a key field that is stored in ViewState.
    This key field is updated by several other controls on the same page.

    I am struggling with the pattern of when to create the table. I can't load
    it in Page_Init as ViewState is not restored. If I load it at Page_Load
    time, I seem to be getting the command name/arguments from the previous
    postback and at times, my dynamic LinkButton fails to fire the command
    event.

    Any suggestions would be appreciated. Thanks,

    Andrew
    Andrew Robinson, Jun 16, 2006
    #1
    1. Advertising

  2. Andrew Robinson

    Teemu Keiski Guest

    Hi,

    generate it so that you create controls in page_load, but set any proeprties
    after you have added the control to Controls collection so that ViewState
    tracking has started. And such, state dependant properties need to be set
    only once inside If Not IsPostBack check (!IsPostBack in C#), e.g
    initially..

    here are a some references

    Understanding ASP.NET ViewState
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp
    Dynamic Web Controls, Postbacks and ViewState
    http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
    Dynamic Controls in ASP.NET
    http://aspnet.4guysfromrolla.com/articles/081402-1.aspx
    Working with Dynamically Created Controls
    http://aspnet.4guysfromrolla.com/articles/082102-1.aspx

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    "Andrew Robinson" <> wrote in message
    news:...
    >I have a <asp:table> control with a large number of dynamically created
    >LinkButtons. I am using the command event, command name and command
    >argument values in my LinkButtons to trigger actions after the post back.
    >The table is dynamically generated based on a key field that is stored in
    >ViewState. This key field is updated by several other controls on the same
    >page.
    >
    > I am struggling with the pattern of when to create the table. I can't load
    > it in Page_Init as ViewState is not restored. If I load it at Page_Load
    > time, I seem to be getting the command name/arguments from the previous
    > postback and at times, my dynamic LinkButton fails to fire the command
    > event.
    >
    > Any suggestions would be appreciated. Thanks,
    >
    > Andrew
    >
    Teemu Keiski, Jun 17, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sef
    Replies:
    4
    Views:
    2,543
    joseph abanila
    Jan 13, 2004
  2. =?Utf-8?B?QkxpVFpXaU5H?=

    Adding dynamic LinkButton to dynamic table

    =?Utf-8?B?QkxpVFpXaU5H?=, Jul 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    698
    =?Utf-8?B?QkxpVFpXaU5H?=
    Jul 27, 2005
  3. Sathyaish
    Replies:
    3
    Views:
    3,079
    Sathyaish
    Sep 8, 2005
  4. Replies:
    6
    Views:
    3,173
  5. Sathyaish

    Linkbutton does not look like a linkbutton

    Sathyaish, Sep 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    170
    Sathyaish
    Sep 8, 2005
Loading...

Share This Page