AsyncPostBackTrigger in nested repeater - asp.net

Good day everyone,
This is my first post in here and I would like to thank you all for the great efforts in this forum by which I have already gaind a lot of skills.
I have a smalle issue with two nested repeaters. Basically, I have a dropdownlist in a child repeater which contains rating values and every time the dropdownlist is changed in the child repeater the new percentange is calculated and presented in a label in the parent repeater. This will cause full postback which is really frustrating when going through too many dropdownlists. My question is how to reflect the new calculated percentange in the label without postback. I have tried to use AsyncPostBackTriggers but no luck. Any suggestions would be appreiciated
<asp:Repeater ID="rptParent" runat="server">
<ItemTemplate>
<asp:Label ID="lblAvg" runat="server" Text='<%# Eval("TrialScore")%>'></asp:Label>
<asp:Repeater ID="rptChild" runat="server">
<ItemTemplate>
<asp:DropDownList ID="lstRate" runat="server" OnSelectedIndexChanged="lstRate_SelectedIndexChanged" />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>

Wrap your aspx mark up inside update panel like this.
<asp:UpdatePanel runat="sever" ID="upParentChild" >
<ContentTemplate>
<asp:Repeater ID="rptParent" runat="server">
<ItemTemplate>
<asp:Label ID="lblAvg" runat="server" Text='<%# Eval("TrialScore")%>'></asp:Label>
<asp:Repeater ID="rptChild" runat="server">
<ItemTemplate>
<asp:DropDownList ID="lstRate" runat="server" OnSelectedIndexChanged="lstRate_SelectedIndexChanged" />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
This will make sure that only controls inside update panel are posted back and not the whole page.

Related

Access model bound item inside nested UpdatePanel

What is the correct method to access the data-bound item inside of a nested UpdatePanel? I've recently discovered model binding and love the strongly-typed binding it offers, but I have a scattering of UpdatePanels throughout the page, and it seems to break access to the Item object. If the entire databound control is inside the UpdatePanel I have no problem. This works:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Repeater runat="server" ID="myRepeater" ItemType="Test.Person">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Item.Name %>' /><br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
But if the UpdatePanel is inside the bound control, I no longer have access to Item. This does not work:
<asp:Repeater runat="server" ID="myRepeater" ItemType="Test.Person">
<ItemTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Label runat="server" Text='<%# Item.Name %>' /><br /> // <-- Problem line
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
CS0103: The name 'Item' does not exist in the current context
I fumbled my way onto a clunky solution, which is this
((Person)GetDataItem()).Name
But I desperately hope this is not the best way of accomplishing the task.

Asyn. LinkButton with controller

I have a updatePanel with a LinkButton and in the LinkButton are some Controller.
<asp:UpdatePanel ID="UpdateRepTrack" runat="server">
<ContentTemplate>
<asp:UpdateProgress ID="updateProgress" runat="server" AssociatedUpdatePanelID="UpdateRepTrack" DynamicLayout="true">
....
</asp:UpdateProgress>
<ItemTemplate>
....
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
....
</ItemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
Now when I click on the Text(Label) the page do a Full Postback, but when I click next to the Text(on the Link directly) then the page do an asynchronous postback.
Can me help someone with a solution so that I get asynchronous postback everywhere.
Thanks.
Solution I have tried
I have tried to add this code behinde
With CType(e.Item.FindControl("LinkButton1"), LinkButton)
Dim trigger As New AsyncPostBackTrigger
trigger.ControlID = .UniqueID
UpdateRepTrack.Triggers.Add(trigger)
End With
I have found a solution. When you add the "clientIDMode" attribute to the linkbutton it works fine.
<asp:LinkButton ID="LinkButton1" clientIDMode="AutoID" runat="server">
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:LinkButton>
I have tried a little round with a clear page. Then I have removed the repeater and it works. After this I found this page
Leonid's space and this was the solution.

Bind Two Dropdown List control with database in VB.NET

I know the way to bind a Dropdown List control with database in VB.NET, but how can I did it if I have two Dropdown List? Both Dropdown List is from same database but what I want to populate on grid view is from Views. Can someone give me some source code to write or any advice is appreciate. Thank in advanced.
<asp:Label ID="Label1" runat="server" Text="Dealer Name:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Choose Dealer</asp:ListItem>
<asp:ListItem>Chai</asp:ListItem>
<asp:ListItem>Chang</asp:ListItem>
<asp:ListItem>Aniseed</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="Recipe: "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>Choose Recipe</asp:ListItem>
<asp:ListItem>Cake</asp:ListItem>
<asp:ListItem>Pie</asp:ListItem>
<asp:ListItem>spaghetti</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
I want for example when choose DropDownList1's dealer and DropDownList2 recipe, the data grid will display the data that I stored in database(Views).

UpdatePanel causing full postback. Trying to do a partial postback

I am working on a page that is using a gridview to display data. I have some dynamically created textboxes inside an ItemTemplate which contains several textboxes per row. Now I also have an update panel that is using ajax and should only render once my link button is clicked. The datalist is bound in my code behind after the I would like this to occur without causing a full postback. However, right now when I click the link button it causes a full post-back which eliminates my dynamically created controls.
I feel I am very close to a solution. I need one of these to happen (option 1 seems more useful):
Do not cause a postback when the linkbutton is clicked, but still render my full datalist in the update panel
or
my dynamically created controls are not removed during post back.
Here is my code:
<ItemTemplate>
[ <asp:LinkButton ID="SelectCommand" CommandName="Select" runat="server" Text="+" CssClass="sunocoBold"/> ]
<%-- start sub panel--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Vertical"
OnItemCommand="DataList_OnItemCommand">
<ItemTemplate>
<asp:LinkButton ID="Select" CommandName="SelectCommand" CommandArgument='<%#Eval("ship_to_num")%>' runat="server" Text='<%#Eval("ship_to_num")%>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<%-- end sub panel--%>
</ItemTemplate>
<asp:TemplateField HeaderText="Site Owner" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Panel ID="pnlNames" runat="server">
</asp:Panel>
<%-- <asp:Literal ID="NameList" runat="server" /> --%>
</ItemTemplate>
</asp:TemplateField>
UpdatePanel.Triggers is made for this!
Take a look at it here: Understanding UpdatePanel.Triggers

Selecting items of a Listview using checkboxes in ASP .NET

I am trying to use checkboxes to select the items in a Listview. I have added a checkbox control in the , and they are displayed properly.
The problem is that Checked property never changes when I click on them. Why does this happen? And is there a workaround?
Here is the code:
<asp:ListView ID="ListView1" runat="server"
onitemcommand="ListView1_ItemCommand"
onitemdatabound="ListView1_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBoxSelect" runat="server" OnCheckedChanged="CheckBoxSelect_checkchanged"/>
<asp:LinkButton ID="LinkButtonOpen" CommandArgument='<%#Eval("MessageID") %>' runat="server">
<asp:Label ID="Label1" Text="[]" runat="server"/>
<%#Eval("FirstName" )%> <%#Eval("LastName")%>
<%#Eval("Subject") %>
<%#Eval("Timestamp") %>
<asp:HiddenField runat="server" ID="ReadStatus" Value='<%#Eval("IsRead") %>' />
</asp:LinkButton>
</ItemTemplate>
</asp:ListView>
I think you are missing the AutoPostBack="true"
<asp:CheckBox ID="CheckBoxSelect" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBoxSelect_checkchanged"/>
The problem was that I was binding the ListView during page load. When that happened, the checkboxes would get cleared, and I got the Checked property as False in all subsequent functions.

Resources