ModalPopupExtender OK Button click event not firing? - asp.net

I have a Button inside an UpdatePanel. The button is being used as the OK button for a ModalPopupExtender. For some reason, the button click event is not firing. Any ideas? Am I missing something?
<asp:updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
<cc1:ModalPopupExtender ID="ModalDialog" runat="server"
TargetControlID="OpenDialogLinkButton"
PopupControlID="ModalDialogPanel" OkControlID="ModalOKButton"
BackgroundCssClass="ModalBackground">
</cc1:ModalPopupExtender>
<asp:Panel ID="ModalDialogPanel" CssClass="ModalPopup" runat="server">
...
<asp:Button ID="ModalOKButton" runat="server" Text="OK"
onclick="ModalOKButton_Click" />
</asp:Panel>
</ContentTemplate>
</asp:updatepanel>

Aspx
<ajax:ModalPopupExtender runat="server" ID="modalPop"
PopupControlID="pnlpopup"
TargetControlID="btnGo"
BackgroundCssClass="modalBackground"
DropShadow="true"
CancelControlID="btnCancel" X="470" Y="300" />
//Codebehind
protected void OkButton_Clicked(object sender, EventArgs e)
{
modalPop.Hide();
//Do something in codebehind
}
And don't set the OK button as OkControlID.

It appears that a button that is used as the OK or CANCEL button for a ModalPopupExtender cannot have a click event. I tested this out by removing the
OkControlID="ModalOKButton"
from the ModalPopupExtender tag, and the button click fires. I'll need to figure out another way to send the data to the server.

It could also be that the button needs to have CausesValidation="false". That worked for me.

I was just searching for a solution for this :)
it appears that you can't have OkControlID assign to a control if you want to that control fires an event, just removing this property I got everything working again.
my code (working):
<asp:Panel ID="pnlResetPanelsView" CssClass="modalPopup" runat="server" Style="display:none;">
<h2>
Warning</h2>
<p>
Do you really want to reset the panels to the default view?</p>
<div style="text-align: center;">
<asp:Button ID="btnResetPanelsViewOK" Width="60" runat="server" Text="Yes"
CssClass="buttonSuperOfficeLayout" OnClick="btnResetPanelsViewOK_Click" />
<asp:Button ID="btnResetPanelsViewCancel" Width="60" runat="server" Text="No" CssClass="buttonSuperOfficeLayout" />
</div>
</asp:Panel>
<ajax:ModalPopupExtender ID="mpeResetPanelsView" runat="server" TargetControlID="btnResetView"
PopupControlID="pnlResetPanelsView" BackgroundCssClass="modalBackground" DropShadow="true"
CancelControlID="btnResetPanelsViewCancel" />

Put into the Button-Control the Attribute "UseSubmitBehavior=false".

None of the previous answers worked for me. I called the postback of the button on the OnOkScript event.
<div>
<cc1:ModalPopupExtender PopupControlID="Panel1"
ID="ModalPopupExtender1"
runat="server" TargetControlID="LinkButton1" OkControlID="Ok"
OnOkScript="__doPostBack('Ok','')">
</cc1:ModalPopupExtender>
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</div>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="Ok" runat="server" Text="Ok" onclick="Ok_Click" />
</asp:Panel>

I often use a blank label as the TargetControlID. ex. <asp:Label ID="lblghost" runat="server" Text="" />
I've seen two things that cause the click event not fire:
1. you have to remove the OKControlID (as others have mentioned)
2. If you are using field validators you should add CausesValidation="false" on the button.
Both scenarios behaved the same way for me.

I've found a way to validate a modalpopup without a postback.
In the ModalPopupExtender I set the OnOkScript to a function e.g ValidateBeforePostBack(), then in the function I call Page_ClientValidate for the validation group I want, do a check and if it fails, keep the modalpopup showing. If it passes, I call __doPostBack.
function ValidateBeforePostBack(){
Page_ClientValidate('MyValidationGroupName');
if (Page_IsValid) { __doPostBack('',''); }
else { $find('mpeBehaviourID').show(); }
}

Related

change control outside UpdatePanel

In short: I want to enable a button i.e. outside UpdatePanel when I click on a button from inside UpdatePanel.
Problem: The button enables but tags i and asp:Localize are not showing in the rendered code after button click from UpdatePanel updPnlOfferings
Detail:
I have a DataList inside UpdatePanel which contains delete button for every item in the list. delete button is firing an event on server which deletes the record and disables a button (i.e. outside of the UpdatePanel.
As someone suggested I kept my button(which need to be disabled) in UpdatePanel below
<asp:UpdatePanel ID="updPnlCourse" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LinkButton ID="lnkDeleteCourseDetails" runat="server" OnClick="lnkDeleteCourseDetails_Click">
<i class="icon-remove-sign"></i>
<asp:Localize ID="Localize6" runat="server" Text="<%$ Resources:CBLabels, LBL_DeleteDetails %>" />
</asp:LinkButton>
<asp:ConfirmButtonExtender ID="lnkDeleteCourseDetails_ConfirmButtonExtender" runat="server"
ConfirmText='Are you sure you want to delete this course?' Enabled="True" TargetControlID="lnkDeleteCourseDetails">
</asp:ConfirmButtonExtender>
</ContentTemplate>
</asp:UpdatePanel>
The Main UpdatePanel which is firing the event is below
<asp:UpdatePanel ID="updPnlOfferings" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlDSOfferings" runat="server">
<asp:DataList ID="dtlstOfferings" runat="server" OnItemCommand="dtlstOfferings_ItemCommand" EnableViewState="true">
</asp:DataList></asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
on dtlstOfferings_ItemCommand event I coded this
lnkDeleteCourseDetails.Enabled = true;
lnkDeleteCourseDetails.ToolTip = "";
lnkDeleteCourseDetails_ConfirmButtonExtender.Enabled = true;
updPnlCourse.Update();
This is a known problem as specified in this link.
The solution is to put all your content that are there inside the LinkButton, within a place holder like below, or make all the child controls as server controls.
<asp:LinkButton ID="lnkDeleteCourseDetails" runat="server" OnClick="lnkDeleteCourseDetails_Click">
<asp:PlaceHolder runat="server">
<i class="icon-remove-sign"></i>
<asp:Localize ID="Localize6" runat="server" Text="<%$ Resources:CBLabels, LBL_DeleteDetails %>" />
</asp:PlaceHolder>
</asp:LinkButton>

Button Click on Enter in asp.net

I have several panels in my page,and each panel has a submit and clearall buttons.
I am trying to set focus of enter to my submit button.
I have an image button in my logo,and everytime user hits enter,its downloading file on imageclick.
Can someone suggest how do i set focus of enter to my submit button.Any ideas?
<asp:Panel ID="Panel2" runat="server" Width="100%" ForeColor="Black" DefaultButton="btnSubmit">
<telerik:RadButton ID="btnSubmit" runat="server" TabIndex="1" OnClick="OnSubmitClick" CausesValidation="true" />
<telerik:RadButton ID="btnclearall" runat="server" OnClick="OnClearAllClick" CausesValidation="false" />
</asp:Panel>
try defaultfocus attribute in <form> tag ,
<form id="form1" runat="server" defaultfocus="btnSubmit" >
Have you tried the UseSubmitBehavior attribute?
<telerik:RadButton ID="btnSubmit" runat="server" TabIndex="1" OnClick="OnSubmitClick" CausesValidation="true" UseSubmitBehavior="true" />
Set the other buttons to false. Technically you shouldn't have to set UseSubmitBehavior to true since it is default but setting all others to false might help.

Checkboxlist inside UpdatePanel triggers full postback when an item is checked

So I have this Checkboxlist and I want to implement a Select All feature for the elements inside it. I placed it inside an UpdatePanel, but everytime I click an item, the entire page is reloaded. This is my code:
<asp:UpdatePanel ID="CBLPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div class="LeftAligned">
<asp:Label ID="FilterLabel" runat="server" Text="Filter by:" />
<asp:DropDownList runat="server" ID="FilterDDL" AutoPostBack="true" OnSelectedIndexChanged="FilterDDL_SelectedIndexChanged" />
<asp:ImageButton ID="FB" runat="server" ImageUrl="~/images/filter.png" AlternateText="VALUE"
CssClass="filter_button" OnClick="FB_Click" />
<div onmouseout="javascript:bMouseOver=false;" onmouseover="javascript:bMouseOver=true;"
class="filter_div">
<asp:CheckBoxList AutoPostBack="true" ID="FilterCheckBoxList" ClientIDMode="Static"
runat="server" CssClass="filter_checklist collapsed" OnSelectedIndexChanged="FilterCheckBoxList_Selected">
</asp:CheckBoxList>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I though I should set ChildrenAsTriggers to false and this way I would update only from the code, but it doesn't seem to work.
This looks like a familiar .NET Bug. Setting ClientIDMode=Auto on the CheckBoxList should fix it

Button onClick event not firing inside a repeater which is in 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.

Popup on mouse enter and hide on mouseout

I was trying to apply a pop up control to a Link button on my ASP.NET website. The popup appears only on button click. How can the behavior be moedified to make the popup appear when on mouseover and ide on mouseout?
Button code:
<asp:LinkButton ID="LinkButton2" CssClass="btn green" ToolTip="NewProfile" Text="NewPlugin"
runat="server" Width="175px" onclick="AddBtn_Click" /><br /><br />
For popup control:
<asp:Panel ID="Panel4" runat="server" CssClass="popupControl">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Administrative previliges are required for this action.
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:PopupControlExtender ID="PopupControlExtender1" runat="server" TargetControlID="LinkButton2" PopupControlID="Panel4" Position="Right">
</asp:PopupControlExtender>
Here is a JQuery Function that does exactly the same thing you are trying to do...
$(".deal-hotel").live('mouseover',
function() {
$(this).find('.deal-hotel-popup').show();
}).live('mouseout',
function() {
$(this).find('.deal-hotel-popup').hide();
});
Yet changing the HTML Attribute for onclick to onmouseover should get you there. Read This
On a side note switching to JQuery will make you like a lot easier.

Resources