I have a button nested inside an update panel which has a CommandArgument tied to it. This calls a method which updates some label and text in an area not contained in the UpdatePanel. If I comment out the update panel the button works correctly so I know it is coming from the update panel. Anyone know how I can pass this through?
protected void Button_Command(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
//update textboxes and labels here
}
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:DataList ID="dListItems" runat="server" DataKeyField="PRODUCT_ID" RepeatColumns="4"
RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False" CellPadding="4">
<HeaderTemplate>
No Record Found....!
</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="Button" runat="server" Text="Add to Cart"
CommandArgument='<%# Eval("Id") %>' CausesValidation="False"
CssClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
OnCommand="Button_Command"
/></span></span></p>
</ItemTemplate>
</asp:DataList>
</div>
</td>
</tr>
</table>
</div>
</ContentTemplate>
which updates some label and text in an area not contained in the
UpdatePanel
That's the problem. UpdatePanel will only update what is within and not what is outside. Try to put those control also the UpdatePanel and see them worked
Related
I have an 2 Update Panel Namely (IDs) as upDMList for UpdatePanel 1 and UpdatePanel2 for second UpdatePanel. I have a Gridview inside UpdatePanel1 which has LinkButton. This Link button need to act as Trigger for second Update Panel but it always shows error
I have tried various methods
For Example - When I target Control using Gridview ID it shows this error
Exception Details: System.InvalidOperationException: A control with ID 'gvDMList$lnkAccountImage' could not be found for the trigger in UpdatePanel 'UpdatePanel2'.
When I Target Control Using only Link Button ID it shows Error
A control with ID 'lnkAccountImage' could not be found for the trigger in UpdatePanel 'UpdatePanel2'.
Even while targetting using Update Panel 1 ID the error is
A control with ID 'upDMList$gvDMList$lnkAccountImage' could not be found for the trigger in UpdatePanel 'UpdatePanel2'.
Both UpdatePanel has ChildrenAsTriggers set to true and ClientIDMode=Static
Any help would be useful
Here is relevant code
`<asp:UpdatePanel ID="upDMList" runat="server" ClientIDMode="Static" ChildrenAsTriggers="true" >
<ContentTemplate>
<div class="table-responsive">
<asp:GridView ID="gvDMList" ClientIDMode="Static" AutoGenerateColumns="false" style="margin: 0 auto" DataKeyNames="DMID" OnRowCreated="gvDMList_RowCreated" OnRowDataBound="gvDMList_RowDataBound" OnRowCancelingEdit="gvDMList_RowCancelingEdit" OnRowEditing="gvDMList_RowEditing" OnRowUpdating="gvDMList_RowUpdating" OnPageIndexChanging="gvDMList_PageIndexChanging" CssClass="table-bordered table-striped table-hover table-condensed" runat="server">
<Columns> <ItemTemplate>
<asp:LinkButton runat="server" CommandName="GetImage" ClientIDMode="Static" CommandArgument='<%#Bind("FileName") %>' ID="lnkAccountImage" OnClick="lnkAccountImage_Click" CssClass="btn btn-primary btn-xs" Text="Show Image"></asp:LinkButton></td>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ControlStyle-CssClass ="btn btn-default" CausesValidation="false" ShowEditButton="true" ShowCancelButton="true"/>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>`
Second Update Panel
<asp:UpdatePanel ID="UpdatePanel2" ChildrenAsTriggers="true" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div class="container">
<asp:Image ID="imgAcnt" CssClass="img-responsive img-thumbnail center-block" AlternateText="Account Details Image" runat="server" />
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnkAccountImage" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I am currently running up against a problem with the UpdatePanel. One of my pages has two User Controls I'll call A and B.
The User Control A has an UpdatePanel containing several ASP TextBox.
<asp:UpdatePanel ID="upA" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" style="position: relative;">
<ContentTemplate>
<-- content here -->
</ContentTemplate>
</asp:UpdatePanel>
The User Control B has an UpdatePanel containing a Panel and an AjaxModalPopup linked to it. In the Panel, there is a Repeater and an ASP button.
<asp:UpdatePanel runat="server" ID="upB" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnActivePopupContainer" runat="server" Style="display: none;" />
<asp:Panel ID="pnlPopupContainer" runat="server" CssClass="modalPopup modalPopupDraggable" Style="display: none;" Width="750px">
<asp:UpdatePanel ID="upPopup" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" ID="pnlHeader" class="header">
<asp:Label ID="Label1" runat="server" Text="<%$ Resources:global, AttentionPopup %>"></asp:Label>
</asp:Panel>
<article>
<asp:Repeater runat="server" ID="rptPopup" OnItemDataBound="rptPopup_ItemDataBound">
<ItemTemplate>
<-- Content -->
</ItemTemplate>
</asp:Repeater>
</article>
<footer>
<div class="or-spacer">
<div class="mask"></div>
</div>
<div class="footer">
<asp:Panel runat="server" ID="pnlBtnBug">
<asp:Button ID="btnOK" runat="server" CssClass="btn yes" Text="<%$ Resources:global, Ok %>" OnClick="btnOK_Click" />
</asp:Panel>
</div>
</footer>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<ajax:ModalPopupExtender ID="popupContainer" runat="server" BackgroundCssClass="modalBackground" PopupControlID="pnlPopupContainer" TargetControlID="btnActivePopupContainer" Drag="true" PopupDragHandleControlID="pnlHeader"></ajax:ModalPopupExtender>
</ContentTemplate>
When the user clicks the OK button of the UserControl B, it triggers a delegate that calls a method in the UserControl A that performs updating of some fields and the update method of the UpdatePanel "upA".
The delegate:
//Delegate Call When the user clicks the ok Button
popup.okHandler = (x) =>
{
A.ChooseOpticienCode(x.Value);
};
in the UserControl A's code behind:
public void ChooseOpticienCode(string code)
{
<-- some treatments -- >
upOpticien.Update(); <-- crash here
}
When the method upOpticien.Update() is called, I get this error:
System.InvalidOperationException: The Update method can only be called on UpdatePanel with ID 'upOpticien before Render.
I don't understand why I get this error. I tried to set the UpdateMode of the UpdatePanel to "Always", the application no longer crashes but the fields are not updated.
ideas ?
I finally found how to fix my problem. Instead of calling the delegate directly, I must use the InvokeMember function so that the delegate is executed correctly and can edit the various fields and update the UpdatePanel
page.GetType().InvokeMember(OkHandler.Method.Name, System.Reflection.BindingFlags.InvokeMethod, null, page, new[] { this });
(here, OkHandler is my delegate)
However, note that using an anonymous method will not work, it's imperative that the delegate points to a method with a name for InvokeMember works.
Here is my scenario..
I have a ListView Control In my ASP.NET Page.
The listview is bound to a datasource.
Then Itemtemplate of ListView makes use of user controls which
include buttons.
The ListView is nested in an UpdatePanel.
I want to set the trigger for the updatepanel to be buttons of UC.
I have come across numerous answers but can't establish a viable solution.
Markup Of UC
<div class="form-group">
<asp:TextBox ID="txtAnswer" runat="server"></asp:TextBox>
</div>
<div class="form-group text-right">
<asp:LinkButton ID="btnUpdateAns" runat="server" OnClick="btnUpdateAns_Click">Update</asp:LinkButton>
<asp:LinkButton ID="btnDelete" runat="server" OnClick="btnDelete_Click" OnClientClick="return confirm('Are you sure to delete the answer?')" CausesValidation="False">Delete</asp:LinkButton>
</div>
Markup OF UC Container
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListView ID="AnswerList" runat="server" DataSourceID="DS_Question">
<ItemTemplate>
<itstar:AnswerControl runat="server" ID="ansBox" propAnswerID='<%# Eval("AnswerID") %>' propQuestionID='<%# Eval("QuestionID") %>'/>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
If your Button is inside ListView then You Could set the Asycronous post for updatepanel on Button Click on ListView RowDataBound
protected void AnswerList_ItemDataBound(object sender, ListViewItemEventArgs e) {
LinkButton lb = e.Item.FindControl("btnUpdateAns") as LinkButton;
toolscriptmanagerID.RegisterAsyncPostBackControl(lb); // ToolkitScriptManager
}
If you need Full Post Back you could RegisterPostBack for the control.May this link will help you out in that case.
I have a ModalPopupExtender with an UpdatePanel inside. The UpdatePanel has a Repeater with a list of LinkButtons.
<asp:Button ID="btnShow" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnShow" PopupControlID="pnl" CancelControlID="btnCancel" />
<asp:Panel ID="pnl" runat="server">
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Repeater ID="rep" runat="server" onitemcommand="rep_ItemCommand">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:Label ID="lblAssignedTo" runat="server" Text='<%# Eval("AssignedTo") %>' />
<asp:LinkButton ID="lnkUnassign" runat="server" CommandName="Unassign" CommandArgument='<%# Eval("Id") %>' />
<ajaxToolkit:ConfirmButtonExtender ID="cbeUnassign" runat="server" TargetControlID="lnkUnassign" ConfirmText="Are you sure you want to unassign this item?" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
protected void rep_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Unassign")
{
//do something
up.Update();
}
}
When I click on a LinkButton, the UpdatePanel should update. It does this but it closes the ModalPopupExtender also.
Is there any way to update the UpdatePanel without hiding the ModalPopupExtender? I can just call ModalPopupExtender.Show(), but the page flickers.
Thanks.
Okay, just found out that there's something wrong with LinkButtons inside Repeaters. Used a Button control instead.
I am dynamically adding buttons to a listview and using the ItemCommand event to handle the button click event using the CommandName property for the button. It works fine in IE, but when I try in Firefox 5, it is hitting the page load event but not the ItemCommand event. Is there a work-around for Firefox?
Thanks!
<asp:ListView ID="lvItems" runat="server" OnItemDataBound="lvItems_ItemDataBound"
DataSourceID="odsItems" OnItemCommand="lvItems_ItemCommand" DataKeyNames="ItemID"
OnDataBound="lvItems_DataBound" OnPagePropertiesChanging="lvItems_PagePropertiesChanging">
<LayoutTemplate>
<div id="itemPlaceholder" runat="server">
</div>
</LayoutTemplate>
<ItemTemplate>
<div>
<asp:Label ID="lbl" runat="server">
</asp:Label>
<asp:Button ID="btnAdd" runat="server" CommandName="Add" Text="Add" OnClientClick="this.disabled=true;" />
</div>
</ItemTemplate>
<EmptyDataTemplate>
No items found for the selected filters. Please try again.<br />
<br />
</EmptyDataTemplate>
</asp:ListView>
protected void lvItems_ItemCommand(object sender,ListViewCommandEventArgs e)
{
if (e.CommandName == "Add")
{
//code here;
}
}
You have to set UseSubmitBehaviour to false, because disabling a button on clientside will cancel the browsers submit. By the way, in IE it's exactly the same.
<asp:Button ID="btnAdd" runat="server" CommandName="Add" Text="Add"
UseSubmitBehavior="false" OnClientClick="this.disabled='true';" />
On this way ASP.NET will append the necessary client-script to postback at the end of your script:
__doPostBack('btnAdd','')
http://encosia.com/disable-a-button-control-during-postback/
OnclientClick and OnClick is not working at the same time?