Reputation: 1382
I recently created a Usercontrol which contains a Listview (databound to a LinqDataSource) added the user control to an existing aspx page (loading the usercontrol dynamically).
I'm seeing an unexpected behavior where the usercontrol is being loaded and listview displayed when we initially load the page, but when I try to click the insert button (from the InsertTemplate of the ListView) the postback occurs, the page reloads but there is no sign of my Listview whatsoever, not even the headers, viewing page source confirms it is completetly gone
The problem is not that the usercontrol is not being reloaded, I can see other elements from the same usercontrol rendering ok.
I've gotten to the point where I've taken the usercontrol and loaded it into a new 'test' aspx page and it works fine there. I've slowly been adding items from my existing page to the test page (javascript,jquery validation,recaptcha, other asp.net controls) and it still works fine. None of the existing controls 'know' anything about the Listview so I can't see how it could be being affected.
Any suggestions as to why this might be happening or debugging options welcome. for now I'm just painstakingly recreating the old page into my testpage but it's time I could be much better using elsewhere.
Next step for me is moving a bunch of linked CascadingDropDowns over to the test page.
update: I've noted another symptom on the postback, the 'ItemInserting' event of the listview is not being triggered.
Upvotes: 1
Views: 3148
Reputation: 13125
Do you have manual binding code such as the following in your listview:
ListView1.DataSource = SomeData;
ListView1.DataBind();
Is this wrapped in a !IsPostback check?
If it is then remove the IsPostback check.
It is also standard operation for the databound control to disapear of the select returns 0 rows. To prevent this you can set up an empty data template.
Upvotes: 2
Reputation: 6986
Check to make sure Viewstate is enabled (shudder). This is usually the cause of this. And don't just check the control itself, check all the way up the control hierarchy, even the page. If Viewstate is disabled anywhere up the hierarchy, that will disable the Viewstate on your control and could cause this issue.
For example:
<asp:Panel ID="pnlMain" runat="server" EnableViewState="false">
<my:Control ID="myControl" runat="server" EnableViewState="true" />
</asp:Panel>
Even though I've set EnableViewState="true"
on my control, it still gets disabled because it's parent's (pnlMain'
's) Viewstate is disabled.
Upvotes: 1