paste plain text ajax custom editor chrome issue - c#

I used below code to paste plain text in my Ajax Custom Editor. It works fine with IE and Firefox. but chrome got screwed.
please help me!
Also, is there a way to access custom editor buttons via c# code, to apply events or get set values
Sys.Application.add_load( function ()
{
editor = $find('<%=Myeditor.ClientID%>'); // Editor's ID="myEditor"
if (editor != null) {
var editPanel = editor.get_editPanel();
editPanel.set_noPaste(true);
}
//---------------------------------------------------
if (Sys.Extended.UI.HTMLEditor.isIE) {
var designMode = Sys.Extended.UI.HTMLEditor.ActiveModeType.Design;
var designPanel = editPanel.get_modePanels()[designMode];
designPanel.captureInDesign = function (ev) {
if (ev.type == "keydown" && ev.ctrlKey && !ev.altKey) {
// key event
if (String.fromCharCode(ev.keyCode).toLowerCase() == "v") {
this._commonPaste(ev);
return false;
}
}
return true;
}
}
});

Related

Prevent Key Event on DevExress ASP.NET MVC SpinEdit

In a form, I have a spin edit control like this:
formLayoutSettings.Items.Add(i =>
{
i.FieldName = "FieldA";
i.NestedExtension().SpinEdit(s =>
{
s.Properties.MinValue = 1;
s.Properties.MaxValue = 9999999999999;
s.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithTooltip;
s.Properties.ClientInstanceName = "seFieldA";
s.Properties.Increment = 10;
s.ShowModelErrors = true;
s.Width = Unit.Percentage(100);
s.Properties.AllowMouseWheel = false;
s.Properties.ClientSideEvents.KeyDown = "OnFieldAKeyDown"; // This is the event heandeler
});
});
And the function:
function OnFieldAKeyDown(s, e) {
if (e.htmlEvent.keyCode == 38 || e.htmlEvent.keyCode == 40) {
ASPxClientUtils.PreventEventAndBubble(e.htmlEvent); // this doesn't work
ASPxClientUtils.PreventEvent(e.htmlEvent); // this either
}
}
My aim is to prevent the spin edit control value from changing when the user presses the Up key or Down keys. When I debug this, the if test inside the OnFieldAKeyDown works but PreventEventAndBubble and PreventEvent fails miserably. Also, is there any other way to do this with jquery ??
Thanks.
AFAIK, there is a workaround to prevent a user incrementing/decrementing SpinEdit value using up/down arrow keys without using PreventEvent or PreventEventAndBubble. When there's no public method available on JS side, you can try restore SpinEdit previous value in KeyDown event handler like this:
<script type="text/javascript">
function OnFieldAKeyDown(s, e) {
if (e.htmlEvent.keyCode == 38 || e.htmlEvent.keyCode == 40) {
// check if ASPxClientSpinEdit exists
if (typeof ASPxClientSpinEdit !== "undefined") {
ASPxClientSpinEdit.prototype.OnPageOrArrowKeyDown = function() {
// when user tries either increment or decrement, it returns last value instead
if (s.GetValue() != s.lastChangedValue) {
s.SetValue(s.lastChangedValue);
}
// if spinedit's minimum & maximum values also affected, set current limit
else {
s.maxValue = ASPxClientSpinEdit.MaxValue;
s.minValue = ASPxClientSpinEdit.MinValue;
}
}
}
}
}
</script>
Combine this function with jQuery may possible, any suggestions welcome.
Reference: https://www.devexpress.com/Support/Center/Question/Details/Q254514

JavaScript client side function not firing for ASP custom validator

I have the following ASP CustomValidator:
<asp:CustomValidator ID="CustomValidator2" runat="server"
EnableClientScript="true" OnServerValidate="ins_server" ClientValidationFunction ="ins_client"
ErrorMessage="CustomValidator"> * Insurance dates not valid without supporting attached document</asp:CustomValidator>
The following C# server side function:
protected void ins_server(object source, ServerValidateEventArgs args)
{
//new user
if (PageMode == PageModes.NewVessel)
{
if (fuAttachment.HasFile && datetimepickerinsend != null && datetimepickerinsstart != null)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
//existing user
if (PageMode == PageModes.EditVessel)
{
args.IsValid = true;
}
}
And also the following client side function in JavaScript stored in a file named customfunctions.js:
//declerations
var insurancestart;
var insuranceend;
var filesattached;
function ins_client(sender, e) {
if (pagemode == 'EditVessel') {
e.IsValid = true;
}
if (pagemode == 'NewVessel') {
if (insurancestart !== '' && insuranceend !== '' && filesattached > 0) {
e.IsValid = true;
}
else {
e.IsValid = false;
}
}
}
I also have the following global variable definition in the ASPX page the control sits on:
<script type="text/javascript">
var pagemode;
$(document).ready(function () {
// removed var to give global scope
pagemode = '<%=this.PageMode.ToString()%>';
});
</script>
My problem is
I have placed a breakpoint on the server side function, every time I click the submit button the server side code is being called and the page refreshes. If I debug in chrome I can see that all my JS variables have the expected values, it just seems like for some reason the client side JS function is not firing and is instead falling over to the server side function.
What was happening here was as #Justin-iurman pointed out, when the function returns true the server side function will also be called after the client. In my case though when I tested a false result I was still going straight to the server side function.
Turns out by pressing F12 in chrome and inspecting the console, I had an undefined error in my JS code. Moving the function in question out of the function used specifically for this page and into global context sorted the issue for me.

How to handle keydown Event in asp.net Textbox?

I have a textbox in web form(asp.net). when user already keyin data, then they will press Enter key, so that the data will be update to database.
Is there any way possible to perform this?
function InitTextBox() {
//var _txt = $('#<%= txt.ClientID%>'); or
var _txt = $('input:[id*="txtId"]');
if (_txt.length < 1) return;
_txt.get(0).autocomplete = 'off';
_txt.on('keydown', function (evt) {
var _self = $(this);
event = evt ? evt : window.event;
if (event.keyCode == 13) {
if ($.browser.msie)
{ event.cancelBubble = true; event.returnValue = false; }
else { event.preventDefault(); }
if (_self.val().length > 0 && _self.val().match(/^\s*$/) == null)
__doPostBack(_self.attr('name'), '');
}
});
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitTextBox);
And set autopostback for textbox to false, please
Dino Esposito had wrote about this a while back. You wouldn't necessarily need a custom control, but can use his JavaScript.
If you have a control wrapped around a Panel, and you have the DefaultButtonID property set, the panel will trigger a postback on enter too by clicking the desired button specified by the ID. That's another way.

how to get client side confirm box value to make server side operations?

I am using Client script for confirm message box as follows
string script = "fadeScript";
ScriptManager.RegisterClientScriptBlock(this.Page, script.GetType(), "Script", "Closewindow();", true);
java script function:
<script type="text/javascript">
function Closewindow() {
var Result = confirm("Are you sure want to delete?");
alert(Result);
if (Result == true) {
document.getElementById('txtConfirmresult').value = Result;//assigning to hidden text box
alert(txtConfirmresult.value);
return true;
}
else
{
document.getElementById('txtConfirmresult').value = Result;//assigning to hidden text box
alert('BYE');
return false;
}
}
</script>
I want to use the script return value in .cs file to excite procedure if it returns true. if it return false i have to stay on that particular page only. plz kindly help me on this
You can use __doPostBack(target, argument) to post back to the server. You can then evaluate __EVENTTARGET and __EVENTARGUMENT in the post data to see what you sent back and perform logic appropriately. Here is a link that provides a little more in depth information.
A quick example:
Script/Client side:
<script type="text/javascript">
function Closewindow() {
var Result = confirm("Are you sure want to delete?");
alert(Result);
if (Result == true) {
var txtConfirmResult = document.getElementById('txtConfirmresult');
txtConfirmResult.value = Result;//assigning to hidden text box
alert(txtConfirmresult.value); //displaying for debug purposes
__doPostBack( 'txtConfirmresult', Result ); //sending back to server.
return true;
}
else
{
document.getElementById('txtConfirmresult').value = Result;//assigning to hidden text box
alert('BYE');
return false;
}
}
C#
protected void Page_Load(object sender, EventArgs e)
{
string target = Request["__EVENTTARGET"];
string argument = Request["__EVENTARGUMENT"];
if (target != null && target.Equals( "txtConfirmresult" ) )
{
this.DoSomeGreatServerSideProcessing(argument);
}
}
Updated to add slightly more correct variable names, but should work with your existing codebase assuming your script was working. I would be very careful using txtConfirmresult as your ID as that will only work if runat="server" is not set on the textbox. If that is the case, the ID will be prepended to denote container hierarchy.
I would suggest naming your "callbacks" very well, such as:
Script/Client side:
<script type="text/javascript">
function Closewindow() {
var Result = confirm("Are you sure want to delete?");
document.getElementById('txtConfirmresult').value = Result;//assigning to hidden text box
if (Result) {
__doPostBack( 'UserConfirmedFormSubmission', "CloseWindow" ); //sending back to server.
return true;
}
else
{
return false;
}
}
C#
protected void Page_Load(object sender, EventArgs e)
{
string target = Request["__EVENTTARGET"];
string argument = Request["__EVENTARGUMENT"];
if (!string.IsNullOrEmpty(target) && target.Equals("UserConfirmedFormSubmission"))
{
if ( !string.IsNullOrEmpty(argument) && argument.equals("CloseWindow"))
{
this.HandleUserRequestedCloseWinow();
}
}
}

Allow checkbox to be disabled in Firefox

So I am working on cross-browser code right now. I have checkboxes, that disable after certain functions are called, in IE but not in Firefox & Chrome.
I looked into the code and I see that when rendered in Firefox, the disabled tag is placed on the td which is why it works in IE and not the other browsers.
Is there a way in asp.net to disable the cell or checkbox and have it render properly in Firefox, Chrome, etc?
Here is my function where enabled = false
protected void FilterCheckBox(object sender, ASPxGridViewTableCommandCellEventArgs e)
{
if (ExecContractGridView != null)
{
try
{
if (ExecContractGridView.GetRowValues(e.VisibleIndex, "UnionExecutedBy") != null)
{
if (!string.IsNullOrEmpty(ExecContractGridView.GetRowValues(e.VisibleIndex, "UnionExecutedBy").ToString()))
{
e.Cell.Enabled = false;
}
}
}
catch (Exception ex)
{
ApplicationLog.Exception(this, ex);
}
}
}
To do this properly you want to find the checkbox control and set disabled = "disabled".
You can do so on the client side using JavaScript or a library like jQuery. Or, in your code above, once you have e.Cell you can locate the CheckBox control and set it to Enabled = false.
To further clarify, e.Cell contains a CheckBox control as one of its child controls. So you could do:
var control = e.Cell.FindControl("SomeCheckBoxControl") as CheckBox;
if (control != null)
control.Enabled = false;

Categories