How To Change Ajax Control Toolkit Controls Button Text - asp.net

Ajax Control Toolkit provides too many useful control and I've use them in a multi language application, nothings bad and everything's fine.
the question is that , How can I change the Ajax Control Toolkit Buttons Text, for example in Confirm Button Extender and vice versa .
any help appreciated

I misunderstood what you were after. To customize the button text, you have to create your own modal and instruct the extender to use it with the DisplayModalPopupID property, like this:
<asp:Button ID="btnCancel" ruat="server" Text="Cancel With Confirm" />
<cc1:ConfirmButtonExtender ID="ConfirmButtonExtender" runat="server"
TargetControlID="btnCancel"
OnClientCancel="cancelClick"
DisplayModalPopupID="MyCustomModal" />
<cc1:ModalPopupExtender ID="MyCustomModal" runat="server"
TargetControlID="btnCancel"
PopupControlID="PNL"
OkControlID="ButtonOk"
CancelControlID="ButtonCancel"
BackgroundCssClass="modalBackground" />
<asp:Panel ID="PNL" runat="server">
Are you sure you want to cancel?
<br /><br />
<div class="buttons">
<asp:Button ID="ButtonOk" runat="server" Text="Yes (Custom!)" />
<asp:Button ID="ButtonCancel" runat="server" Text="No (Custom!)" />
</div>
</asp:Panel>

Related

ValidationGroup Not working with Custom Asp.NET control

I have a custom ASP.NET control that was created by inheriting from WebControls.ImageButton. In my markup I have the following
<td>
<CustomControlLibrary:CustomIcon ID="icnSave" CausesValidation="true" OnClick="DoSomething"
runat="server" Enabled="true" IconUse="Add" AutoSkin="true" SupportsEvents="true" ValidationGroup="ValidationGroupA" />
<asp:LinkButton ID="lbSave" OnClick="DoSomething" CausesValidation="true"
runat="server" ValidationGroup="ValidationGroupA">SAVE</asp:LinkButton>
</td>
When I click the "SAVE" link, the validation works as expected, however when I click on the CustomIcon, the validation does not work, and the DoSomething wired to the OnClick fires off.
Is there anything special that needs to be added to the custom controls to get ValidationGroups to work? Note: The CustomIcon control itself does not have any special validation that it does/
Sorry i don't know this line .
<CustomControlLibrary:CustomIcon ID="icnSave" CausesValidation="true" OnClick="DoSomething"
runat="server" Enabled="true" IconUse="Add" AutoSkin="true" SupportsEvents="true" ValidationGroup="ValidationGroupA" />
If you want to image button ,please try this sample
<asp:textbox id="tb1" runat=Server />
<asp:requiredfieldvalidator id="ReqField1" controltovalidate="tb1"
validationgroup="valGroup1" errormessage="Required" runat=Server />
<asp:ImageButton id="Button2" causesvalidation=true
validationgroup="valGroup2" ImageUrl="img.gif" runat=Server />
Demo

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.

AsyncPostBack FileUpload on a ModalPopup

I am using a UpdatePanel, and my submit button is one of the triggers along with the clear button. But the problem is I have a FileUpload Control in the div. This is a modal popup, so it displays a form for a user to upload a little note. When I try to upload a file with AsyncPostBackTrigger it does nothing (which I have read about). My question is how do I not use the PostBackTrigger because I want to use the asyncpostbacktrigger because if an error occurs, then the Modal popup closes and the user doesnt know if the file was uploaded or not. What can I do?
Code:
<asp:Panel ID="addnotepanel" runat="server" style="/*display:none;*/" CssClass="addnotepanel">
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ClrBtn" />
<asp:PostBackTrigger ControlID="SubmitBtn" />
</Triggers>
</asp:UpdatePanel>
File:
<br />
<asp:Label ID="ErrorLabel" runat="server" Visible="False"></asp:Label>
<br />
<asp:Button ID="Submitbtn" runat="server" Text="Submit"
onclick="Submitbtn_Click" />
<asp:Button ID="CnlBtn" runat="server" Text="Cancel" onclick="CnlBtn_Click" />
<asp:Button ID="ClrBtn" runat="server" onclick="ClrBtn_Click"
Text="Clear" />
</div></asp:Panel>
keep SubmitBtn as a PostBackTrigger but dont set it as the "OkControlID" of the modalpopupextender.
in the Submitbtn_Click server side sub, call yourModalpopupextenderID.hide() if the upload is completed so the Modal pop up closes only if there is no error.
You could use a AsyncFileUpload from the AjaxControlToolkit
Here, as an exemple some code to show how to use it :
<AjaxControlToolkit:AsyncFileUpload ID="AttachementsFileUpload"
runat="server"
OnUploadedComplete="AttachementsFileUpload_UploadedComplete"
OnClientUploadComplete="uploadComplete" />
<script type="text/javascript">
var UpdateAttachementsGridViewButton = '<%= UpdateAttachementsGridViewButton.ClientID %>';
function uploadComplete(sender, args) {
$get(UpdateAttachementsGridViewButton).click();
}
</script>
As you see, when the upload is complete, I use Javascript to trigger an click on an hidden button. Meanwhile I retrieve the file in the AttachementsFileUpload_UploadedComplete using something like this:
Dim AttachementsFileUpload As AjaxControlToolkit.AsyncFileUpload = AnnouncementFormView.FindControl("AttachementsFileUpload")
Attachements.add(e.filename, AttachementsFileUpload.FileBytes)
It's how I used it in my situation, but you will find plenty of examples on how it work

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.

ModalPopupExtender OK Button click event not firing?

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(); }
}

Resources