Professional Web Applications Themes

UserControls and DataBound Repeater - ASP.NET Building Controls

I've built a few UserControls that have worked perfectly for a while. Now, for the first time, I want to use these controls inside a Data-Bound Repeater control. When the page first loads, my control works perfectly. But any kind of PostBack results in runtime errors in the control's PageLoad(), when it tries to do SomeProperty = ViewState["SomeProperty"].ToString() where it says that there's a NULL Exception (I guess that this means that the value of my ViewState["SomeProperty"] is NULL. Perhaps you can help me understand how things change in the situation where my control is inside a Repeater so that ...

  1. #1

    Default UserControls and DataBound Repeater

    I've built a few UserControls that have worked perfectly for a while. Now,
    for the first time, I want to use these controls inside a Data-Bound Repeater
    control.

    When the page first loads, my control works perfectly. But any kind of
    PostBack results in runtime errors in the control's PageLoad(), when it tries
    to do
    SomeProperty = ViewState["SomeProperty"].ToString()
    where it says that there's a NULL Exception (I guess that this means that
    the value of my ViewState["SomeProperty"] is NULL.

    Perhaps you can help me understand how things change in the situation where
    my control is inside a Repeater so that I can try to figure out why this is
    happening?

    Thanks.

    Alex
    Alex Maghen Guest

  2. #2

    Default RE: UserControls and DataBound Repeater

    Hello Alex,

    Thank you for posting.

    Is this usercontrol you're developing still the one over mentioned in your
    former threads? As for hosted in databinding repeater control scenario, the
    only difference is that when the repeater control is performing
    databinding( repeater.DataBind method is called), it will populae
    repeaterItems and perform databinding on all the sub controls in each
    repeaterItem(include your usercontrol if it is put in the repeater
    control). Also, since your ascx usercontrol has its own databinding (in
    page_load ) code logic, it may conflict with page's databinding (when the
    repeater.dataBind cause the usercontrol in repeaterItem to databind ).
    Generally, I would change the original databinding code into the "DataBind"
    override method in my usercontrol. e.g.

    ========in ascx code behind======

    public override void DataBind()
    {
    base.DataBind();

    PerformDataBind();

    }
    ==============

    PerformDataBind() is the method which encapsulate the code to query
    database and populate the dropdownlist ....

    As for the ViewState error you mentioned, I think it's a control specific
    problem, would you provide your current version of the usercontrol so that
    I can have a look on it?

    Regards,

    Steven Cheng
    Microsoft MSDN Online Support Lead


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)



    Steven Cheng[MSFT] Guest

  3. #3

    Default RE: UserControls and DataBound Repeater

    Hi Alex,

    How are you doing on this issue, have you got any further progress? Please
    don't hesitate to let me know if you need any help on this.

    Regards,

    Steven Cheng
    Microsoft MSDN Online Support Lead


    ==================================================

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.



    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Steven Cheng[MSFT] Guest

Similar Threads

  1. UserControl with databound repeater drops values on postback
    By paul.hester@gmail.com in forum ASP.NET Building Controls
    Replies: 3
    Last Post: September 2nd, 07:11 AM
  2. UserControls ASP.NET 2.0
    By Giovanni in forum ASP.NET Building Controls
    Replies: 0
    Last Post: April 24th, 11:16 PM
  3. .NET databound radiolistbutton in a repeater
    By Rod Snyder in forum Dreamweaver AppDev
    Replies: 3
    Last Post: February 18th, 11:36 PM
  4. Replies: 1
    Last Post: April 8th, 11:23 PM
  5. Using UserControls in a DLL
    By Rory in forum ASP.NET Building Controls
    Replies: 5
    Last Post: July 29th, 07:30 AM

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