.net user control event handler lost on postback

Posted by user154008 on Stack Overflow See other posts from Stack Overflow or by user154008
Published on 2009-08-11T12:54:41Z Indexed on 2012/09/23 15:38 UTC
Read the original article Hit count: 248

Filed under:
|
|
|
|

I have a menu usercontrol called LeftMenu that has a bulletedlist of linkitems. It's on the ascx page as such:

<asp:BulletedList ID="PublisherList" DisplayMode="LinkButton" OnClick="PublisherList_Click" cssClass="Menu" runat="server"></asp:BulletedList>

I databind the list in the page_load under if(!isPostBack)

I'm having an issue on a page that loads the control. When the page first loads, the event handler fires. However, when the page posts back it no longer fires and in IE8, when I'm debugging, I get "Microsoft JScript runtime error: Object expected" in Visual Studio pointing at "doPostBack('LeftMenu$PublisherList','0')." In FF I don't get the error, but nothing happens. I'm **not loading the control dynamically, it's loaded on the aspx page using:

<%@ Register TagPrefix="Standards" TagName="LeftMenu" Src="LeftMenu.ascx" %>

<Standards:LeftMenu ID="LeftMenu" runat="server"/>

Any ideas of where I'm losing the event handler?

I just realized this is happening on another user control I have as well. A text box and a button and I'm using the default button to make sure pressing the enter key uses that button. .Net converts that in the html to:

 <div id="SearchBarInclude_SearchBar" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'SearchBarInclude_QuickSearchButton')">

so as soon as i enter a key in the box I get a javascript error at the line saying "object expected." It seems like the two issues are related.

Edit Again: I think I need to clarify. It's not that I'm clicking on the menu item and it can't find the selected item on postback. I have this search page with the left navigation on it and then the main content of the page is something that causes a postback. Everything is fine with this postback. Once that page has been posted back, now if I click on the bulleted list in the left navigation I get a javascript error and it fails. The page_init for the LeftMenu control is never called.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET