Asyn. LinkButton with controller - asp.net

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.

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.

AsyncPostBackTrigger in nested repeater

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.

Image Button does a Complete post-back on every click.

Is there anyway i can prevent a ImageButton control to avoid complete post back at the same time trying to fetch the some information on button click ?
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="litRowStart" runat="server"></asp:Literal>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<td >
<ul>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl='<%#String.Format(Eval("Image_Location")+".jpg") %>' CssClass="thumbnail" ToolTip = '<%# Eval("Team_Name")%>' />
<asp:Label ID="Label2" runat="server" Font-Bold="True" Text='<%# Eval("serno")%>' Visible="false"/>
</ContentTemplate>
</asp:UpdatePanel>
</ul>
</td>
<asp:Literal ID="Literal2" runat="server"></asp:Literal>
<asp:Literal ID="litRowEnd" runat="server"></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
On the backend i am doing :
Label1.Text = ((Label)e.Item.FindControl("Team_Id")).Text;
But every time I Click the image button it does a post back instead of a Asynchronous one.
There is a lot of data on the page which is depending on the Serno.
Can someone please suggest me a solution or an alternative to Image Button which will perform the same functionality with a button click.
Thank You !
You can use this code that can detect which control did post back and correct your code:
string ctrlName = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(ctrlName))
ctrl = FindControl(ctrlName);
if (IsPostBack && ctrl!=ImageButton2)
{
//your code that will execute in postback
}
This should work. Can you make sure you have no js error and HTML is valid on the page?

How to set a download counter on Hyperlink Control inside Repeater? asp.net

I have a hyperlink inside a repeater control for the list of pdf. I want to set a download counter on each click on each hyperlink. The FileName must be a parameter. My code is basically like below. There is also code that calls stored procedure and bind it to the repeater on page_load.
<asp:Repeater ID="rptPDF" runat="server">
<ItemTemplate>
<div class="repeaterResources">
<b><%# Eval("Name") %></b><br />
<b>Description</b> <%# Eval("Description") %><br />
<asp:HyperLink ID="HyperLink2" runat="server" class="downloadLink" NavigateUrl='<%# "~/PDF/" & Eval("Filename") %>' Target="_blank">Download</asp:HyperLink><br /><br />
</div>
</ItemTemplate>
</asp:Repeater>
The mystery bit is how to get a button click event from here. Thanks.
You can use the OnCommand event and set the CommandArgument attribute with a value using
<%# Eval('myvalue') %>.
MSDN has an example minus the repeater: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.oncommand.aspx
Sample:
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="button1" OnCommand="button1_command" CommandArgument='<%# Eval("myvalue") %>' />
</ItemTemplate>
</asp:Repeater>

Listview inside UserControl raises full postback

I have UserControl and within that control i have asp:ListView. Inside the ListView i have a asp:LinkButton. When i click on the LinkButton the control raises full postback, no matter if the UserControl is inside UpdatePanel or is not.
UserControl:
<asp:ListView ID="lvImages" runat="server" OnItemCommand="lvImages_ItemCommand">
<ItemTemplate>
<div>
<asp:Image runat="server" ID="imgImageThumb" ImageUrl='<%#Eval("Image") %>' GenerateEmptyAlternateText="true" />
<asp:LinkButton runat="server" ID="lbtnImageAdd" CommandName="Add" CommandArgument='<%#Container.DisplayIndex %>'
CausesValidation="false" Text="Add" />
</div>
<ItemTemplate>
</asp:ListView>
Page:
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<cuc:UserControl ID="cucUserControl" runat=server/>
</ContentTemplate>
</asp:UpdatePanel>
You need to set the properties to let the update panel know what to trigger off of. Try setting ChildrenAsTrigger=true.

Resources