Showing posts with label jscript. Show all posts
Showing posts with label jscript. Show all posts

Wednesday, March 28, 2012

Page_Validator undefined Error??

Hi,

I have a jscript function calledEnableAll(). The following is the Function:-

function EnableAll()

{

alert("Hai");

EnableAllValidators(false);

EnableValidator('valreq_Salutation',true);

ShowError();

}

This i called on a button click. but only the alert message is pop_up. after that im getting this errorPage_Validators is undefined Jscript runtime error .

What was the solution for this??

How can i over come this...

Hi,

I'm not quite sure why you use this function. It seems you want to enable all validators on the page according to the name of the function.

The error is caused by an javascript exception, looks like it uses an object that doesn't exist internally. And I can't tell since I don't know your implementation in EnableAllValidators and EnableValidator function. You'd better use Visual Studio to debug your javascript to find out the reason and resolve it.

Wednesday, March 21, 2012

parseLocale ignores negative currency format

I have some JScript that is utilized by a custom TextBox control that does various validation and format functions on the client side. In particular, when the control receives focus I left-justify the value in the textbox and format it without currency and grouping characters. Just the raw number. Then when the control loses focus (blur), I re-format the contents based on a property that indicates which formatting to use. This custom TextBox accepts only numeric input. In the case of a curreny input (DisplayFormat = "C") and a negative number, the number is formatted using the current culture's CurrencyNegativePattern of CultureInfo.NumberFormat. AJAX handles all of this for me since I call the Number.localeFormat function. The problem is that when the TextBox receives focus, I try to strip all formatting to get the raw number but for a negative currency value AJAX'sparseLocale function does not recognize the parantheses that are added to the number when it is formatted bylocaleFormat. Example: -1000 is formatted as ($1,000.00) with a format string of "C2" but when you pass this toparseLocale you get "1000.00". Shouldn'tparseLocale recognize the negative patterns its counterpartlocaleFormat adds to the value?

function numberEditorFocus(src)
{
src.style.textAlign ='left';
var displayFormat ="D";
if (src.value !="")
{
var val = Number.parseLocale(stripCurrency(src.value));
alert(val);
if (isNaN(val) ==false)
{
var newValue = val.localeFormat(displayFormat);
src.value = newValue;
}
src.select();
}
}

Sounds like it may be a bug, take a look in the source code for the AJAX Framework or theissues list

-Damien


Nothing in the bug list. It's obvious from the source code in the AJAX library that the parseLocale (and subsequently the parse) function does not consider the negative currency pattern. It only accounts for the preceding +/- sign. So, is this a bug or is there some reason it was designed with way? AJAX team?

Number.parseLocale = function Number$parseLocale(value) { /// <param name="value" type="String"></param> /// <returns type="Number"></returns> var e = Function._validateParams(arguments, [ {name: "value", type: String} ]); if (e) throw e; return Number._parse(value, Sys.CultureInfo.CurrentCulture);}Number.parseInvariant = function Number$parseInvariant(value) { /// <param name="value" type="String"></param> /// <returns type="Number"></returns> var e = Function._validateParams(arguments, [ {name: "value", type: String} ]); if (e) throw e; return Number._parse(value, Sys.CultureInfo.InvariantCulture);}Number._parse = function Number$_parse(value, cultureInfo) { var valueStr = value.trim(); if (valueStr.match(/infinity/i) !== null) { return parseFloat(valueStr); } if (valueStr.match(/^0x[a-f0-9]+$/i) !== null) { return parseInt(valueStr); } var numFormat = cultureInfo.numberFormat; var decSeparator = numFormat.NumberDecimalSeparator; var grpSeparator = numFormat.NumberGroupSeparator; var numberFormatRegex = new RegExp("^[+-]?[\\d\\" + grpSeparator + "]*\\" + decSeparator + "?\\d*([eE][+-]?\\d+)?$"); if (!valueStr.match(numberFormatRegex)) { return Number.NaN; } valueStr = valueStr.split(grpSeparator).join(""); valueStr = valueStr.replace(decSeparator, "."); return parseFloat(valueStr);}


I'd modify the source and recompile for now so that it works for you, and I would log this as a bug...

-Damien

Partial Postbacks and JScript Changes Previously Made on the Client Side

Hello, thank you in advance for taking the time to read this.

I have a Gridview on which I use client-side JScript to add an empty row (hidden) after binding. I place several hidden DIVS in my Gridview template, and then when a user clicks on one of several "expand" buttons in the Gridview, the empty row is made visible and the innerHTML is swapped from the appropriate hidden DIV. This makes the empty row sort of a "Jack of all trades" in that it can display numerous different things as needed by the user.

I am attaching the JScript function below for reference. The empty DIVS are inserted into the client page in the Codebehind using the Gridview's OnRowDataBound handler, but I have no clue how to add a row dynamically server-side, so I went with the client-side script to get the container row done.

Everything works great until you do a sort. The control is AJAX-enabled, so refreshes through a partial postback. Trouble is that the client-side code that adds all the rows does not fire when the grid is refreshed, so none of the "Expand" icons work after the Gridview has been refreshed, because there is no hidden row to make visible and swap content with.

After all this, my question is: How might I:

A) insert an empty row programatically server-side, or

B) fire a client-side script at databinding on a partial postback.

Oh, and I am a pure short-busser when it comes to .NET -- love it but am just now moving up from legacy and feel like a complete idiot. Please speak slowly if you care to answer, and forgive my ignorance.

Javascript adding the rows follows -- I am assigning an ID reference to each row using the "Tracking" field - a unique DB column.

Thanks again for reading, and for any information or hlp you can provide.

Shannon

function fixGrid(idGrid){

var al ="";

var rowcount = 0;for (var t=0;t<idGrid.childNodes[0].childNodes.length-1;t++){

thisName = idGrid.childNodes[0].childNodes[t].nodeName;

if(thisName=="TR"){

rowcount ++;

if(rowcount > 1){

lastCell = idGrid.childNodes[0].childNodes[t].childNodes.length;

thisCell = idGrid.childNodes[0].childNodes[t].childNodes[lastCell-1];

thisTrack = idGrid.childNodes[0].childNodes[t].childNodes[lastCell-2].innerText;

newTR = document.createElement('tr');

newRow1 = newTR.cloneNode(true);

newTD = document.createElement('td');newCol1 = newTD.cloneNode(true);

newCol1.colSpan=9;

newCol1.style.visibility='hidden';

newCol1.style.display='none';

newCol1.id ="td-"+thisTrack;

newCol1.innerHTML="Nothing";

newTR.appendChild(newCol1);

nextRow = idGrid.childNodes[0].childNodes[t].nextSibling;

tableTop = idGrid.childNodes[0].childNodes[t].parentNode;

tableTop.insertBefore(newTR,nextRow);

t++;

}

}else{

alert(thisName);

}

}

returnfalse;

}

Problem solved! I figured I would answer myself for the benefit of future readers.

The call to the client side code in my original post is made fromfixGrid(document.all.gridedit)when the page originally loads.

Obviously, I only want to add the empty container rows once, so I only want this script to be called once each time UpdatePanel1 refreshes, and not if any other panel does. Got it to work that way usingRegisterClientScriptBlock with the update panel ID:

protectedvoid Page_PreRender(object sender,EventArgs e)

{

string script =@."fixGrid(document.all.gridedit);";ScriptManager.RegisterClientScriptBlock(

UpdatePanel1,

typeof(Page),

"ToggleScript",

script,

true);

}