asp.net - UpdatePanel sometimes refreshing entire page -
even though using update panel, entire page refreshed, , can't figure out why.
(edited take account jason p's answer.)
masterpage code:
<form runat="server" id="form1"> <asp:scriptmanager id="scriptmanager1" runat="server" enablepartialrendering="true" /> <h1>title</h1> <asp:updatepanel id="updatepanel1" runat="server" updatemode="conditional" childrenastriggers="true"> <contenttemplate> <ul class="letterlinks"> <asp:repeater runat="server" id="letter_repeater"> <itemtemplate> <li id='<%#eval("letter")%>'> <asp:linkbutton runat="server" id="updatelink" text="my text" commandname="bookletter" commandargument='<%#eval("letter")%>' oncommand="loadbooktitles"/> </li> </itemtemplate> </asp:repeater> </ul> <ul class="booklist"> <asp:repeater runat="server" id="title_repeater"> <itemtemplate> <li><a href='<%#eval("url")%>'><%#eval("title")%></a></li> </itemtemplate> </asp:repeater> </ul> </contenttemplate> </asp:updatepanel> </form>
code behind:
public partial class mybooks : system.web.ui.masterpage { private getallbookinfo setmyinfo = new getallbookinfo(); private datatable alltitleinfo = new datatable(); protected void page_load(object sender, eventargs e) { list<string> letterswithbooks = new list<string>(); datatable letterlinks = new datatable(); // letters have books letterswithbooks = setmyinfo.letterswithbooks(); // properties abc links letterlinks = getletterlinkproperties(letterswithbooks); // bind abc link data abc repeater letter_repeater.datasource = letterlinks; letter_repeater.databind(); alltitleinfo = setmyinfo.getbooktitles(letterswithbooks[0]); // bind title info data title repeater title_repeater.datasource = alltitleinfo; title_repeater.databind(); } private datatable getletterlinkproperties(list<string> letters) { datatable letterlinks = new datatable(); letterlinks.columns.add("letter", typeof(string)); letterlinks.columns.add("class", typeof(string)); letterlinks.columns.add("enabled", typeof(bool)); (char c = 'a'; c <= 'z'; c++) { if (letters.any(letter => letter == c.tostring())) { letterlinks.rows.add(c, "hasguides", true); } else { letterlinks.rows.add(c, "noguides", false); } } return letterlinks; protected void loadbooktitles(object sender, eventargs e) { linkbutton letterlink = (linkbutton)sender; alltitleinfo = setmyinfo.getbooktitles(letterlink.commandargument string); // bind title info data title repeater title_repeater.datasource = alltitleinfo; title_repeater.databind(); } }
not sure if entire problem, <triggers>
element should on same level <contenttemplate>
element, not child:
<asp:updatepanel> <triggers> ... <triggers> <contenttemplate> ... <contenttemplate> </asp:updatepanel>
also, believe in case, repeater should trigger, not linkbutton. try removing oncommand event linkbutton , adding repeater, , changing updatepanel's trigger.
Comments
Post a Comment