TODO:
Have you ever had an empty content editable element, which means the only way to get focus to it was to tab to it?
SOLUTION:
Enclose your element in a <div class="editableCell">. Then track the click on the div, setting focus to it's first child, which will be your empty content editable element. See the JQuery code below.
$(document).on('click', '.editableCell', onClick);
//So we need this because when there is an empty contenteditable element it wont take a click. So we need to get the parent (TD) then set focus to the SPAN which will allow data entry.
function onClick(e) {
$(e.target).children('span')[0].focus();
}
NOTES:
You can change the 'span' to whatever your contenteditable element is. In my case it was a span.
TODO:
Have you ever wanted to validate a page on the client side?
SOLUTION:
if (Page_ClientValidate("vgForgotPassword")) {
//do something
}
NOTES:
If the validation group does not have a name use ""
TODO:
You are using a Telerik RadButton, and you want to display a Confirm Dialog, and capture the user pressing cancel, thus canceling the Postback.
SOLUTION:
<!-- Define button, and put method to call in the OnClientClicking event -->
<telerik:RadButtonID="btnDelete"runat="server"Text="Delete Customer"OnClick="btnDelete_Click"
OnClientClicking="ConfirmDelete">
</telerik:RadButton>
<!-- Confirm action here. Cancel press in this dialog will return FALSE, which in turn we will catch and set cancel = true in the args -->
<telerik:RadCodeBlockID="RadCodeBlock1"runat="server">
<scripttype="text/javascript">
function ConfirmDelete(sender, args) {
if (!confirm('Delete Customer, do you wish to proceed?')) {
args.set_cancel(true);
}
}
</script>
</telerik:RadCodeBlock>
NOTES:
You may not need the RadCodeBlock, I did in this case due to Application
TODO:
Have you ever wanted to add the onblur or onfocus event to a TextBox in the Codebehind?
SOLUTION:
//add focus
myTextbox.Attributes.Add("onfocus", "MyJavascriptFocusFunction(this);");
//add blur
myTextbox.Attributes.Add("onblur", "MyJavascriptBlurFunction(this);");
NOTES:
There are no notes on this topic.
TODO:
Have you ever wanted to "click" a button when someone presses return on a Textbox? The code below, goes in the codebehind of your aspx file.
SOLUTION:
myTextBox.Attributes.Add("onkeypress", "if(event.keyCode==13) {document.getElementById('" + myButton.ClientID + "').click(); return false;}");
NOTES:
There are no notes on this topic.
TODO:
Have you ever wanted to execute some javascript before an async postback? Place the below code in your aspx file, just under the Main Content Placeholder, or body tag if you are not using a master page.
SOLUTION:
<script type="text/javascript">
//add the init activity
Sys.Application.add_init(appl_init);
//Do this on init
function appl_init() {
var pagegReqManager = Sys.WebForms.PageRequestManager.getInstance();
pagegReqManager.add_beginRequest(BeginHandler);
}
//Called before async postback
function BeginHandler() {
MyJavascriptMethod();
MyOtherJavascriptMethod();
}
</script>
NOTES:
There are no notes on this topic
TODO:
Have you ever wanted to execute some javascript after an async postback? Place the below code in your aspx file, just under the Main Content Placeholder, or body tag if you are not using a master page.
SOLUTION:
<script type="text/javascript">
//add the init activity
Sys.Application.add_init(appl_init);
//Do this on init
function appl_init() {
var pagegReqManager = Sys.WebForms.PageRequestManager.getInstance();
pagegReqManager.add_endRequest(EndHandler);
}
//Called after async postback
function EndHandler() {
MyJavascriptMethod();
MyOtherJavascriptMethod();
}
</script>
NOTES:
There are no notes on this topic