DataGrid Viewstate

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kpg

    #1

    DataGrid Viewstate

    Hola,

    I have a datagrid with button columns. I bind the data on
    page load, and the table is read only, so I don't need the
    datagrid viewstate enabled. When I turn it off however, I
    no longer get the button click events. I know events are
    passed in the viewstate, but I don't need the data saved in
    the viewstate, it adds a considerable amount of data to the
    page.

    Can I tunn off the datagrid viewstate and still respond to
    button column events?

    kpg
  • Winista

    #2
    Re: DataGrid Viewstate

    As long as you can provide a mechanism for the DG state to be restored by
    PageLoad, the event will fire. Without viewstate DG can't restore its state.





    "kpg" <no@way.com> wrote in message
    news:Xns97D9631 32D710ipostther eforeiam@207.46 .248.16...[color=blue]
    > Hola,
    >
    > I have a datagrid with button columns. I bind the data on
    > page load, and the table is read only, so I don't need the
    > datagrid viewstate enabled. When I turn it off however, I
    > no longer get the button click events. I know events are
    > passed in the viewstate, but I don't need the data saved in
    > the viewstate, it adds a considerable amount of data to the
    > page.
    >
    > Can I tunn off the datagrid viewstate and still respond to
    > button column events?
    >
    > kpg[/color]


    Comment

    • kpg

      #3
      Re: DataGrid Viewstate

      As Winista once said in microsoft.publi c.dotnet.framew ork.aspnet
      [color=blue]
      > As long as you can provide a mechanism for the DG state to be restored
      > by PageLoad, the event will fire. Without viewstate DG can't restore
      > its state.
      >
      >
      > http://www.netomatix.com[/color]


      OK, but when I click the button on the datagrid, I get a postback, but
      neither the DataGrid1_ItemC ommand nor DataGrid1_Selec tedIndexChanged
      events get called.

      All I need to know from the page is which column the user clicked
      on, but this info seems to be lost without viewstate enabled.

      Comment

      • Winista

        #4
        Re: DataGrid Viewstate

        Exactly... if DataGrid state is not resored or for that matter page's state
        is not restored, framework does not know where to send the message. You can
        use approach where you can set custom IDs or string in __EVENTTARGET and
        __EVENTARGS hideen variables from client side when click happens and then on
        server you can look for these values to decide from where the event
        originated.

        "kpg" <no@way.com> wrote in message
        news:Xns97D967B B0CE57ipostther eforeiam@207.46 .248.16...[color=blue]
        > As Winista once said in microsoft.publi c.dotnet.framew ork.aspnet
        >[color=green]
        >> As long as you can provide a mechanism for the DG state to be restored
        >> by PageLoad, the event will fire. Without viewstate DG can't restore
        >> its state.
        >>
        >>
        >> http://www.netomatix.com[/color]
        >
        >
        > OK, but when I click the button on the datagrid, I get a postback, but
        > neither the DataGrid1_ItemC ommand nor DataGrid1_Selec tedIndexChanged
        > events get called.
        >
        > All I need to know from the page is which column the user clicked
        > on, but this info seems to be lost without viewstate enabled.
        >[/color]


        Comment

        • kpg

          #5
          Re: DataGrid Viewstate

          As Winista once said in microsoft.publi c.dotnet.framew ork.aspnet


          Works great!


          In the DataGrid1_ItemD ataBound event I added (see ref below):


          If e.Item.ItemType <> ListItemType.He ader And _
          e.Item.ItemType <> ListItemType.Fo oter Then

          Dim myButton As Button = e.Item.Cells(0) .Controls(0)

          myButton.Attrib utes("onclick") = _
          "javascript : document.getEle mentById ('__EVENTTARGET ').value=" & _
          DataBinder.Eval (e.Item.DataIte m, "UserID") & ";"

          End If

          and in the Page_Load (see ref below):

          Dim strTest As String = Page.Request.Pa rams("__EVENTTA RGET")


          Ref:





          Thanks.

          Comment

          Working...