I have a linkbutton inside a repeater, and I need it to have an id in order to trigger a modal popup extender, but it is not working since the id is not correct due to the repeater.
<asp:Repeater ID="repeaterSessions" runat="server" OnItemCommand="repeaterSessions_OnItemCommand">
<ItemTemplate>
<p>
<%# ((Academia.SessionEN)Container.DataItem).Title %>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Select" CommandArgument=<%#Eval("id") %>></asp:LinkButton>
</p>
</ItemTemplate>
</asp:Repeater>
After this we have the modal popup extender which triggers the linkbutton1:
<ajaxToolkit:ModalPopupExtender ID="LinkButton1_ModalPopupExtender" runat="server" Enabled="True" TargetControlID="LinkButton1" PopupControlID="Panel1">
I tried to add a new linkbutton1 outside the repeater with the id linkbutton1, and it works, but I'd like to know if it is possible to trigger this from inside the repeater.
Thanks everyone!
EDIT: It would also be a possibility to trigger the modal popup extender from the code behind function, but I don't know how to do it either.
Related
I have a RadioButtonList inside of Repeater and I want to select just one option at a time. But for each RadioButtonList created dynamically I can select multiple options in each RadioButtonList.
How can I select one option and deactivate the previous selection?
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="ItemBound">
<ItemTemplate>
<h4><label id="header" runat="server"><%# Eval("Description") %></label></h4>
<asp:UpdatePanel ID="panel" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="rdo" RepeatDirection="Vertical" runat="server" OnSelectedIndexChanged="rdo_SelectedIndexChanged" AutoPostBack="true" ClientIDMode="AutoID"></asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</ItemTemplate>
</asp:Repeater>
When a control is rendering in a list bound control, the ID is changed to be unique so JavaScript can work with it. There is a great forum post here about this, and it includes a work-around.
http://forums.asp.net/t/1378112.aspx?RadioButtonList+in+a+Repeater+GroupName
I have an ItemCommand event in a button found in a listview.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListView ID="systemsView" runat="server"
onitemcommand="systemsView_ItemCommand">
<ItemTemplate>
<asp:Button ID="btnView" runat="server" Text='<%#Eval("SYSTEM_DESC") %>' CommandArgument='<%# Eval("ROW_ID")%>'
class="systemButtonStyle" />
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
When the itemCommand is fired I want to bind another gridview which is not inside the update panel. The gridview is not showing when the event is fired. Any ideas how I could solve this problem please?
Since UpdatePanels only perform a PostBack on controls within their ContentTemplate, all controls that are expected to be updated by a Partial PostBack must be housed within the same UpdatePanel's ContentTemplate.
If you need to update something outside of an UpdatePanel with an action that occurs within it's Partial PostBack, you will have to rethink your use of the UpdatePanel.
Two solutions:
Add the other GridView to the UpdatePanel's ContentTemplate.
Remove the UpdatePanel entirely and use the normal PostBack.
I have a search form in an updatePanel which retrieves a list of users in a grid in the same UpdatePanel. The name of each user is a commandLink. I want to make the commandLinks as PostBackTriggers.
But when I do it I get an error at the pageLoad time that the controlId does not exist and its true because the grid of users does not render at the load time but through an ajax call.
Any ideas on how can I make the multiple command buttons in a grid retrieved through ajax call as post back triggers?
When adding the items to the grid, within the ItemDataBound event handler, you should register the postback for each specific control (the static identifiers in your HTML declarations are essentially placeholders - not all things repeated in the grid can actually have the same ID). You do this using the ScriptManager.RegisterAsyncPostBackControl method:
The RegisterAsyncPostBackControl method enables you to register Web
server controls as triggers so that they perform an asynchronous
postback instead of a synchronous postback. When the
ChildrenAsTriggers property of an UpdatePanel control is set to true
(which is the default), postback controls inside the UpdatePanel
control are automatically registered as asynchronous postback
controls.
As stated above, using ChildrenAsTriggers is a possibility, too, but this is commonly set to false for more stringent management.
I have found the solution. Here is the code on asp
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" />
<asp:GridView ID="gvSearchResult" runat="server" OnRowCommand="gvSearchResult_RowCommand"
OnRowDataBound="gvSearchResult_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnDetail" runat="server" CommandArgument='<%# Bind("CNIC") %>' CommandName="Detail">
<asp:Label ID="lblName" Text='<%# Bind("Employee_Name") %>' runat="server</asp:Label>
</asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle"Height="25px"Width="30%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Ihad to place OnRowDataBound="gvSearchResult_RowDataBound" on gridView and that function looks like below. So I had to register the iterative control in Scriptmanager as PostBackControl in RowDataBound event of GridView.
protected void gvSearchResult_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if ((e.Row.RowType == DataControlRowType.DataRow))
{
LinkButton lnkbtnDetail = (LinkButton)e.Row.FindControl("lnkbtnDetail");
ScriptManager.GetCurrent(this).RegisterPostBackControl(lnkbtnDetail);
}
}
catch (Exception ex)
{
}
}
<asp:Repeater ID="Cartridges" runat="server" onitemcommand="Cartridges_ItemCommand">
<ItemTemplate>
<p class="cartqty">QTY <asp:TextBox ID="cartQty" Text="0" runat="server"></asp:TextBox></p>
<div class="cartbuy2"><asp:LinkButton ID="buy" runat="server" CommandName="AddtoCart" CommandArgument='<%#Eval("cartID") %>' Text="Buy"></asp:LinkButton></div>
</ItemTemplate>
</asp:Repeater>
Why does the TextBox cartQty only return the default value of 0 rather than the value entered and submitted? If I change the value to 3 it submits 3 regardless of what's typed.
Here's the codebehind for cartQty
LinkButton lb = (LinkButton)e.CommandSource;
int varCartQty = Convert.ToInt32(((TextBox)lb.Parent.FindControl("cartQty")).Text);
Thank you ;-)
I can only guess:
You are binding the Repeater to it's DataSource on every postback but not only if(!Page.IsPostBack)
I doubt your repeater is rebinded. When you click the button your page_load event is called before your click handler, where your repeater is binded.
So you need to take care of that.
if(!IsPostBack)
{
//Put repeater binding code here
}
I have a repeater control in which i have loaded questions. I want to display a textbox and a button when some one click the question and answer that question with out posting back the page. the textbox and button get hide when the user post the answer
U could do this with ajax using an UpdatePanel.
The javascript will be generated for you by the ASP.NET engine.
You can learn more on the UpdatePanel here.
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<span onclick="ShowTextBox(<%# Container.ItemIndex %>)"><%# Eval("Question") %> </span>
<div style="display:none" id='<%# "dv_"+Container.ItemIndex %>'>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Button" />
</div>
</ItemTemplate>
</asp:Repeater>
AND Add some script
`<script type="text/javascript">
function ShowTextBox(index) {
$("#dv_" + index).show();
}
</script>`
Remember you should include the jquery file in the head.
download from jquery.com