Is it possible to tie one modalpopupextender to multiple target controls (multiple buttons)?
Thanks
Behrouz
Good Answer, I will just add to it:
For me I had to change onclick to OnClientClick:
<asp:Button ID="btn_contact2" runat="server"
OnClientClick="javascript:$find('popup1').show();return false;"
Text="Possibilites" />
You need to add a BehaviorID to the modalpopup:
BehaviorID="popup1"
I don't think you can specify multiple targets for the ModalPopupExtender. But you can call it from other controls via JavaScript by adding something like this to their onclick handler:
<act:ModalPopupExtender id="mpePopup" runat="server" BehaviorID="bePopup" ... />
<asp:Button id="btnOther" runat="server" Text="Open Dialog" OnClientClick="$find('bePopup').show();return false;" />
The key is to provide a value for "BehaviorID" in the extender control. This enables client-side access via the "$find(behaviorID)" method, from which you can ".show()" or ".hide()" the modal popup.
Related
Let's say I've got an asp:button on a website which I'm trying to track to count how many times it has been clicked by different users.
<asp:Button ID="SubBtn" runat="server" OnClick="Button1_Click" runat="server" Text="Sub" />
In my code behind I've got a redirect link to a different page.
I'm aware that I need to include something like
<a href="#" name="button1" onclick="dataLayer.push({'event': 'button1-click'});" >Button 1</a>
Do I need to convert my asp:button to a html button to make this work?
You need to use attribute "OnClientClick":
<asp:Button ID="SubBtn" runat="server" OnClick="Button1_Click" runat="server" Text="Sub" OnClientClick="dataLayer.push({'event': 'button1-click'});" />
You can read more about this attribute on MSDN: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick(v=vs.110).aspx
I have defined form action in my asp page and with in form, I have defined the Textbox OnTextChanged. but when I type any thing on Textbox and click on tap to move next.. automatically instead of calling OnTextChanged ..my form action calls..
my code is below
<form id="WebToLead" action="https://url" method="POST" runat="server">
<asp:TextBox id="a" name="a" maxlength="10" runat="server" OnTextChanged="a_TextChanged" AutoPostBack="true" />
// some more textbox
<asp:Button ID="Button2" Text="Click" width="50px" runat="server" OnClick="Button2_Click" />
</form>
Means it action should be triggered on button2_click but it does when i type anything on aand tap to other fields
Ensure you have viewstate enabled for this to work, otherwise Asp.Net has no way of knowing whether the control's value has changed.
AutoPostBack is enabled thats why it is posting the form back to server. Remove it or disable it. It should work after that.
I have ASP.NET WebForms application. One of it's pages is dynamically created table with RegularExpressionValidator. Above of table there are several LinkButtons, which manages navigation of application. But if I put invalid value to textbox in table, Page.IsValid is set to false and all controls on page are blocked.
So, how can I unblock buttons even if validator set Page.IsValid to false? Thnak you.
You could use ValidatorGroups to separate the validations.
Assuming you want to "unblock" the link buttons used for navigation, you can use:
CausesValidation="False"
in the ASPX markup for the link button.
Example:
<asp:LinkButton ID="btnBack" runat="server" data-transition="fade" CausesValidation="false"
data-theme="b" data-icon="" Text="Back" onclick="btnBack_Click" />
I want to create a simple Yes/No popup window. So I have added a ModalPopupExtender to the .aspx page.
The popup panel's markup is:
<asp:Button ID="btn_yes" runat="server" Text="Yes" onclick="btn_yes_Click" />
<br/>
<br/>
<asp:Button ID="btn_no" runat="server" Text="No" />
For some reason, I cannot get into the function btn_yes_Click, not sure why. Do I have to use Javascript?
I suspect that you are also setting the ModalPopupExtenders OkControlID property to "btn_yes".
As you can see in this related question this will cause the OnClick event not to fire.
There is a chance that the OKControlID Property on ModalPopupExtender tag is specified. Take a look at this topic: The Event Handler of the OK button inside a Modal PopUp is not executing
I would like to know how I can control the 'Enabled' property of a button based on the 'checked' value of a checkbox:
<asp:CheckBox ID="chkEnableButton" runat="server" />
<asp:Button ID="btnLoadForm" runat="server" />
I can do this very easily on the server side - but I require this to be done on client side only, meaning JavaScript. Would the OnCheckedChanged attribute allow me to call some JavaScript to do this....or is it strictly for calling a handler in the code-behind?
Just to clarify, when the checkbox is checked, the button is enabled... when the checkbox is unchecked the button is disabled.
Javascript:
<script type="text/javascript">
function checkButt(obj) {
document.getElementById('<%=btnLoadForm.ClientID%>').disabled = !obj.checked;
}
</script>
Web Controls:
<asp:CheckBox ID="chkEnableButton" runat="server" OnClientClick="checkButt(this);" />
<asp:Button ID="btnLoadForm" runat="server" />
This SO question might give you a hint of how to do this. In your situation however, instead of changing the text of the Checkbox, find the Button control on your page and change it's disabled property.
You can use here ClientID attribute so you can get the control on client side via javascript using document.getElementById or document.forms[0].elements[clientID].
function enableButton() {
$get('<%= btnLoadForm.ClientID %>').disabled = !$get('<%= chkEnableButton.ClientID %>').checked;
}
<asp:CheckBox ID="chkEnableButton" runat="server" OnClientClick="enableButton()" />