I am annoyed with a problem I have repeater control in updatepanel like this.
<asp:UpdatePanel ID="UpdPnlConstituentRepeater" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Repeater ID="repConstituentInformation" runat="server" OnItemDataBound="repConstituentInformation_ItemDataBound">
<ItemTemplate>
<asp:DropDownList ID="dropRegistrantDownCostType" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" OnSelectedIndexChanged="dropRegistrantDownCostType_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Text="Select Type" Value="0" Selected="True" />
</asp:DropDownList>
<asp:CheckBoxList ID="chkBoxListRegistrantBenefits" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged">
</asp:CheckBoxList>
</itemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
The problem I face that whenever I select any value from dropdown all the page gets refreshed After spending hours on the google I found a solution i.e, on itemdatabound event of repeater we just need to add the following code after finding the dropdown,
Dim sm As ScriptManager = ScriptManager.GetCurrent(Page)
sm.RegisterAsyncPostBackControl(objDropdownlist)
It worked very well for the dropdown but same is not working for checkboxlist like using the scripmanager instance if I write sm.RegisterAsyncPostBackControl(chkBoxListRegistrantBenefits), it is not working :(
Add ClientIDMode="AutoID" to the Repeater control.
You should not have to add any triggers and you should not even have to call RegisterAsyncPostBackControl. The ChildrenAsTriggers should take care of that.
on Repeater ItemDataBound event
use screiptmanager method RegisterAsyncPostBackControl
this.ScriptManager1.RegisterAsyncPostBackControl(
e.Item.FindControl(" put here your checkbox ID "));
Add this Before start of <ContentTemplate>:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="objDropdownlist" EventName="OnSelectedIndexChanged" />
</Triggers>
Related
I have put an update panel in a page and its working properly.In that page i was
loading an repeater and its also working properly.But inside that repeater i am firing an event "OnSelectedIndexChanged" in a dropdownList .while using it the page is getting refreshed. seems update panel is not working over there.
<asp:UpdatePanel ID="update_invest" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Repeater ID="rptinvest" runat="server" OnItemDataBound="rptactions_ItemDataBound">
<ItemTemplate>
<td>
<asp:DropDownList ID="ddlemployee" runat="server" OnSelectedIndexChanged="ddlEmployee_SelectedIndexChanged"
AppendDataBoundItems="true" AutoPostBack="True">
</asp:DropDownList>
</td>
</ItemTemplate>
</asp:Repeater>
the above is the code....!!
Thanks Arshad..!
I think you need to register the postback triggering controls inside update panel. In your code snippet, it is ddlemployee. If it was in the mark up, you can do so like:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlemployee" EventName="OnSelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
However, drop down control is nested inside repeater that you have to register it from code behind like:
For Each item As RepeaterItem In rptinvest.Items
Dim ddlemployee As DropDownList = DirectCast(item.FindControl("ddlemployee"), DropDownList)
ScriptManager1.RegisterAsyncPostBackControl(ddlemployee)
Next
Hope this help you. Visit here for more information about update panel and triggers.
I have a DropDownList with the following markup:
<asp:UpdatePanel id="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<asp:DropDownList id="ddlCampaignModule" runat="server" OnSelectedIndexChanged="ddlDynamicType_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="-1">None</asp:ListItem>
<asp:ListItem Value="10">Category Menu</asp:ListItem>
<asp:ListItem Value="11">Best Sellers</asp:ListItem>
<asp:ListItem Value="12">Best Reviews</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
In the code behind I select the second option Category Menu. If I run my code and select any other option it posts back to ddlDynamicType_SelectedIndexChanged however if I re-select the second option (after selecting one of the other ones) my postback isn't triggered.
Am I missing something simple here?
Sounds like you are always selecting the 2nd option in the code behind, regardless of postback... ensure you only do that if it isn't!
if (!IsPostBack)
{
//select 2nd Item
}
I am trying to update a DataTable on selection Index Changed event of DropdownList.
What I want is when I select/change dropDownList Item, the Selected Value should be saved into the database without Page refresh(without AutoPostback).
You will need to set AutoPostback to true.
But you can use an update panel to do a partial PostBack and not refresh the complete page.
See here
Use it like this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true" >
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>item 1</asp:ListItem>
<asp:ListItem>item 2</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
I know I am missing something simple but I can't seem to get my button to post back. This is how my form looks (simplified):
<asp:ScriptManager id="smMembersArea" runat="server" EnableViewState="False" />
<asp:UpdatePanel id="updAccounts" runat="server" EnableViewState="True">
<ContentTemplate>
<asp:Repeater id="rptrWishList" runat="server" EnableViewState="False">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:Button id="bWLAmend" onclick="FEdit" runat="server" cssclass="button bg" EnableViewState="True" Text="GO"/>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
The update panel doesn't do anything and nothing happens in FEdit.
When I remove the updatepanel my FEdit event is triggered correctly.
Can anyone point me in the right direction please.
Thanks.
what you can do is add CommandName="Select" to your button
so your button now looks like this
<asp:Button id="bWLAmend" onclick="FEdit" runat="server" cssclass="button bg" EnableViewState="True" Text="GO" CommandName="Select"/>
and use itemcommand of the repeater rptrWishList_ItemCommand
so when you click the button, itemcommand event of repeater fires.
what language you are using in code behind..?I may be able to suggest something else.
I have a repeater and the items are editable through an edit button which opens a FormView in edit mode. The formView is initially invisible and the repeater visible. Once edit is pressed the repeater goes invisible then the formview becomes visible with the item to edit.
Once changes have been made the user presses update. This sets the formview invisible and the repeater visible.
The problem is the formview goes invisible but the repeater doesn't become visible. This I think is caused by the fact the formview is within an update panel and the repeater isn't? Only the items in the update panel are being altered on clicking update because it is only a partial page update.
I can't put the repeater within the update panel because there is a requirement that the public view doesn't use javascript.
Does anyone know how I could make the repeater reappear?
<asp:Repeater id="resultsRepeater" runat="server" DataSourceID="vehiclesDataSource" >
<ItemTemplate>
<asp:Label id="makeLabel" runat="server" Text='<%# Eval("Make") %>' />
<asp:Button id="editButton" runat="server" Text="Edit" CommandArgument='<%# Eval("Id") %>' OnClick="EditButton_Click" />
</ItemTemplate>
<asp:Repeater>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Panel id="insertUpdatePanel" runat="server" Visible="false">
<asp:FormView id="editformview" runat="server" DataKeyNames="Id" Datasourceid="VehiclesEditDataSource" >
<EditItemTemplate>
<uc:VehiclesEdit ID="VehiclesEdit" runat="server" />
<asp:Button id="updateButton" runat="server" OnClick="Update_Click" />
</EditItemTemplate>
</asp:FormView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
protected void EditButton_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = false;
insertUpdatePanel.Visible = true;
}
protected void Update_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = true;
insertUpdatePanel.Visible = false;
}
This might help. I had a similar problem and this worked for me. I simply used ScriptManager to register the button (even iterated by row) as a postback control like this:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(updateButton)
This caused a full postback and allowed me to set the visibility of a panel outside the update panel. I hope it works!
REVISED: Add a PostBackTrigger to your UpdatePanel to force a full post-back when your UpdateButton is clicked. This will hide your UpdatePanel and reveal your Repeater again. See final code below:
For more info refer to: https://stackoverflow.com/questions/2545508/how-do-i-force-full-post-back-from-a-button-within-an-updatepanel
<asp:UpdatePanel ID="updatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="updateButton" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Visible="false">
<asp:FormView ID="editformview" runat="server" DataKeyNames="Id" DataSourceID="VehiclesEditDataSource">
<EditItemTemplate>
<uc:vehiclesedit id="VehiclesEdit" runat="server" />
</EditItemTemplate>
</asp:FormView>
<asp:Button ID="updateButton" runat="server" OnClick="Update_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>