Control missing property after postback with repeater

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Control missing property after postback with repeater

    I am frustrated and not sure where to turn for help.

    I have a custom control that has been working fine. The custom control is
    composed of a dropdownlist and button. I have placed the control in a
    repeater and it works just fine.

    I have added a query filter at the top of the page where I create a new
    datatable and rebind with the repeater. This is where the problem occcurs.
    If I redirect to the page and execute the new query and rebind everything is
    fine. If however, i postback the controls in the repeater do not seem to
    have any properties and hence i get an error.

    I would expect that this might be easy solution but i do not know what it
    is.

    I have implemented
    Implements IPostBackDataHandler
    Implements INamingContainer

    One of the properties looks like the following (within the custom control)
    Public Property DataTextField() As String
    Get
    If CType(ViewState("DataTextField"), Object) Is Nothing Then
    Return _dataTextField
    Else
    Return CType(ViewState("DataTextField"), String)
    End If
    End Get
    Set(ByVal value As String)
    ViewState("DataTextField") = value
    Me.DropDownList.DataTextField = value
    _dataTextField = value
    End Set
    End Property

    and also within the LoadPostData I do
    Me.DataTextField = ViewState("DataTextField") and me.datatextfield has a
    value after the postback.
    The problem occurs when I try to rebind the same repeater with a new
    datatable.

    I do not understand how the postback would react differently than the page
    load.

    Any help would be very much appreciated.
    thx
    dave
    dave Guest

  2. Similar Questions and Discussions

    1. UserControl with databound repeater drops values on postback
      Hi all, I have a user control that contains a repeater that generates a list of check boxes. The checkboxes render fine, but they don't maintain...
    2. Control Not remembering property on postback
      Hi, where in the lifecycle / events you reading/writing the value? Init, Load, postback event, PreRender...? -- Teemu Keiski ASP.NET MVP,...
    3. Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback
      Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Hi, I have simple Itemplate implementation with 2...
    4. Missing ID property for a custom control
      Hello, When i'm using a custom control in my project, i can see that the custom control is missing it's ID in the HTML file. I can see the object...
    5. Composite control delegating databound templated features to child <asp:repeater> control
      Hi Everybody, I'm creating a composite control in C# that basically renders a bunch of webcontrols such as <asp:Label />, <asp:Repeater />,...
  3. #2

    Default Re: Control missing property after postback with repeater

    > and also within the LoadPostData I do
    > Me.DataTextField = ViewState("DataTextField") and me.datatextfield has a
    > value after the postback.
    > The problem occurs when I try to rebind the same repeater with a new
    > datatable.
    >
    > I do not understand how the postback would react differently than the page
    > load.
    Wrong approach. The PageLoad happens much after LoadPostData.

    LoadPostData means that there is an 'input' element with the corresponding
    ClientID in the form.
    Also, it is not a good idea to implement INamingContainer and
    IPostBackDataHandler simultaneously.

    IPostBackDataHandler is meant for single elements.
    INamingContainer is meant for multi-elements.

    btw, can you elaborate what exactly you are trying to achieve. May be you
    never need IPostBackDataHandler etc... which would be the case 99% of the
    time.

    --
    Happy Hacking,
    Gaurav Vaish | [url]http://www.mastergaurav.org[/url]
    [url]http://www.edujini.in[/url] | [url]http://webservices.edujini.in[/url]
    -------------------


    Gaurav Vaish \(www.EduJini.IN\) Guest

  4. #3

    Default Re: Control missing property after postback with repeater

    > IPostBackDataHandler is meant for single elements.

    Or to be precise... HTML form elements.


    --
    Happy Hacking,
    Gaurav Vaish | [url]http://www.mastergaurav.org[/url]
    [url]http://www.edujini.in[/url] | [url]http://webservices.edujini.in[/url]
    -------------------


    Gaurav Vaish \(www.EduJini.IN\) Guest

  5. #4

    Default Re: Control missing property after postback with repeater

    After the postback, i am able to get the old and current values of the
    control (i.e. the value of the dropdown item selected). The problem occurs
    when the page renders (after the postback) there is nothing selected in the
    dropdown list and the values in the dropdown list are now empty.
    i.e. the value of ViewState("DataTextField") or _dataTextField is now empty.
    I was expecting that after the postback and render to the page that this
    value would be retrieved for the population in the grid.
    Remember, this control is located within a repeater which may be what is
    complicating this situation.
    After the postback, i do not rebind the repeater to the datasource (as I
    would have expected that the values in the controls (custom) would have
    remained in tact after the postback).

    If necessary i can send or make available the source code of my control. I
    really do need some help with this issue. THank you dave
    dave Guest

Posting Permissions

  • You may not post new threads
  • You may 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