Is there way to update listbox in loop? I have an updatepanel with a listbox.
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="updateButton" EventName="Click"/>
</Triggers>
<ContentTemplate>
<asp:ListBox ID="lbUpdatedCompanies" runat="server" Height="300px" style="margin-top: 0px" Width="374px"></asp:ListBox>
<br/>
<asp:Button ID="updateButton" runat="server" OnClick="UpdateButtonClick" Text="Обновить"/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress" runat="server" AssociatedUpdatePanelID="UpdatePanel">
<ProgressTemplate>
<img src="../Icons/loading_spinner.gif" style="height: 60px; width: 65px" alt=""/>
</ProgressTemplate>
</asp:UpdateProgress>
On button click I'm trying to add items to listbox in loop:
foreach (var company in companies)
{
lbUpdatedCompanies.Items.Add(company.NAME);
Thread.Sleep(1000);
}
But the listbox shows changes after loop exit when all items are added
Related
here is my aspx code
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txt_newPayment" runat="server" Style="text-align: center" onblur="if(this.value=='')this.value=this.defaultValue;" value="0" onfocus="if(this.value==this.defaultValue)this.value='';" class="form-control"
Font-Bold="True" Font-Size="XX-Large" Height="50px" ontextchanged="txt_newPayment_TextChanged">0</asp:TextBox>
<asp:Label ID="Label5" runat="server" Text="Change: " Style="text-align: center;
font-size: 20px; color: black" Font-Bold="True"></asp:Label>
<asp:Label ID="lblChange" runat="server" Text="N/A" Style="text-align: center; font-size: 20px; color: green" Font-Bold="True"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txt_newPayment" EventName ="TextChanged"/>
</Triggers>
</asp:UpdatePanel>
the very problem is this code is not firing the textchange event in my c#
protected void txt_newPayment_TextChanged(object sender, EventArgs e)
{
}
It seems that, your code looks good and all the required tags were placed for update panel issue, but one small problem AutoPostBack="True" was missed in the above Textbox control. Just add this attributes to the textbox control it will surely trigger the event.
Hope it was useful,kindly share your thoughts or feedbacks
thanks
karthik
I have three dropdowns on a page.
(1) Holds Parking Structures - parkingArea
(2) Holds the levels for the selected (1) - ddParkingAreaLevel
(3) The slots available for (2) - ddAvailableParkingSlots
When someone changes (1), (2) is uploaded with the levels for (1) and then (3) is updated with the slots available for the level selected (2).
However, this just does not work. I am not very familiar with UpdatePanel and simply cant get it to work as intended.
They way it works now:
When I change (1), (2) is updated correctly and (3) loads the slots for (2). But, if I change (2), the UpdatePanel is triggered but slots are NOT loaded into (3) and (2) "jumps back" to SelectedIndex at value 0, and does not stay at the newly selected level.
Here is the code:
<div class="form-group" id="parkingArea" runat="server">
<label>Parking Area:</label>
<asp:DropDownList ID="ddParkingAreas" CssClass="form-control" runat="server"
style="width:240px;" onselectedindexchanged="ddParkingAreas_SelectedIndexChanged"
AutoPostBack="true"></asp:DropDownList>
</div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="form-group">
<label>Level:</label>
<asp:DropDownList ID="ddParkingAreaLevel" CssClass="form-control" runat="server"
style="width:240px;" onselectedindexchanged="ddParkingAreaLevel_SelectedIndexChanged"
AutoPostBack="true"></asp:DropDownList>
</div>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="ddParkingAreas"
EventName="SelectedIndexChanged" /></Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="form-group">
<label>Available Parking Slots:</label>
<asp:DropDownList ID="ddAvailableParkingSlots" CssClass="form-control"
runat="server" style="width:240px;"></asp:DropDownList>
</div>
</ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="ddParkingAreaLevel"
EventName="SelectedIndexChanged" /></Triggers>
</asp:UpdatePanel>
Hope any of you guys can help!
Regards,
Bob
Why not use one update panel for all cascading dropdowns?
<asp:UpdatePanel ID="udpMain" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<div class="form-group" id="parkingArea" runat="server">
<label>Parking Area:</label>
<asp:DropDownList ID="ddParkingAreas" CssClass="form-control" runat="server" style="width:240px;" onselectedindexchanged="ddParkingAreas_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</div>
<div class="form-group">
<label>Level:</label>
<asp:DropDownList ID="ddParkingAreaLevel" CssClass="form-control" runat="server" style="width:240px;" onselectedindexchanged="ddParkingAreaLevel_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
</div>
<div class="form-group">
<label>Available Parking Slots:</label>
<asp:DropDownList ID="ddAvailableParkingSlots" CssClass="form-control" runat="server" style="width:240px;"></asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddParkingAreas" EventName="ddParkingAreas_SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddAvailableParkingSlots" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
I have a couple of buttons in an update panel that gets disabled from code behind on certain triggers like depending it wrote to database or not. Now on the client i have a reset button, This button resets all components on the page like a asp:dropdown, textbox etc, except for the ones in the update panel. I'm usning a javascript to reset it but these ones in the update panel never gets reset. Any help will be appreciated.
<td valign="top" align="center" width="50%">
<asp:UpdatePanel ID="updTxtGen" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtGenVVOE" name= "txtGenVVOE" TextMode="MultiLine"
runat="server" style="font-size: 11px" rows="4" cols="44" Width="324px>
</asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCreateNote" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td></tr>
<tr> <td valign="top" align="center" width="50%">
<asp:UpdatePanel ID="updateCopy" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button name ="btnCopy" ID="btnCopy" class="btn" runat="server"
onmouseover="this.className='btn btnhov'"
onmouseout="this.className='btn'" style="background: silvergradient"
Text="COPY" OnClientClick="ClipBoard();return false;"
ToolTip="Copy Text to ClipBoard" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnCreateNote" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
and my JS script is very simple , i get the
document.getElementById('btnCopy').enabled = true;
document.getElementById('txtGenVVOE').enabled = true;
Like I mentioned , all elements get reset except the ones disabled from code behind.
A quick google search suggests this might be the answer:
document.getElementById('btnCopy').disabled = false;
document.getElementById('txtGenVVOE').diabled = false;
Why am not sure, why I am receiving this warning or error for my update panel,
text is not allowed between the opening and closing tags update panel
Here;s markup
<script type="text/javascript">
function bringPOPup()
{
$.blockUI({message: $('#anotherUP'), css: { width: '600px' } });
}
</script>
<div id="anotherUP" style="display: none; cursor: default">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:DropDownList ID="drop1" runat="server" EnableViewState="true" AutoPostBack="true" OnSelectedIndexChanged="Drop1_SelectedIndexChanged"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostbackTrigger ControlID="drop1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<input type="button" id="Button3" value="Click me to Bring Pop Up" onclick="bringPOPup()" />
<br />
</ContentTemplate>
</asp:UpdatePanel>
Can someone tell me whats wrong as I googled it and nothing is coming up as wrong.
What this error is indicating is that you can't have plain text directly inside an UpdatePanel - the only things that can be an immediate child of the UpdatePanel are <Triggers> and <ContentTemplate>.
Here's an example of what's not allowed:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
You can't put text right here, this will cause an error!
<ContentTemplate>
<input type="button" id="Button3" value="Click me to Bring Pop Up" onclick="bringPOPup()" />
<br />
</ContentTemplate>
</asp:UpdatePanel>
The text I added outside the ContentTemplate will cause that error.
I don't see anything in the code you've shown so far that would cause the error, but that is what you need to look for. It's probably somewhere in code elsewhere on the page.
I have a page displaying post with comments and subcomments , each comment have a reply linkbutton when clicked it shows a textbox and a button to add subcomments, the problem is the linkbutton only works the 1st and 2nd time .... the third time nothing happnes i tried debugging it and i get nothing at all it didn't go to the server here is the code
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="addComment_btn" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server"
onitemdatabound="Repeater1_ItemDataBound"
onitemcommand="Repeater1_ItemCommand">
<ItemTemplate>
<ol class="cosmo-comment-list cosmo-comment-plain">
<li class="comment even thread-even depth-1" id="li-comment-2">
<div id="comment-2" class="comment-body">
<asp:HiddenField ID="commentID_hidden" runat="server"
Value='<%# Eval("comments_ID") %>' />
<div class="cosmo-comment-thumb"><img alt="" src="images/default_avatar.jpg" class="avatar avatar-60 photo" height="60" width="60"></div>
<div class="cosmo-comment-leftpointer"></div>
<div class="cosmo-comment-quote">
<div class="cosmo-comment-textinfo">
<span class="user"><%# Eval("commenter_name")%></span>
<span class="time"><%#Eval("comment_date")%> </span>
<span class="gray reply fr"><a class="comment-reply-link" href="#">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LinkButton ID="reply_linkbtn" runat="server" Visible="false" CommandName="reply">Reply</asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="reply_linkbtn" />
</Triggers>
</asp:UpdatePanel>
</a></span>
</div>
<p> <%# Eval("text") %> </p>
</div>
</div>
</li>
</ol>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="reply_linkbtn" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="subcomment_textbox" runat="server" Visible="false"></asp:TextBox>
<asp:Button ID="add_subcomment_btn"
runat="server" Text="Button" Visible="false"/>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Edit: Problem fixed it was in the code behind I don't know the actual reason but in the page load I always called the repeater.Databind() method and that caused the problem... when i made a condition if (!IsPostBack) and then bind the data the problem was fixed