.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

What would make array.length return an incorrect number?

Posted By:      Posted Date: October 03, 2010    Points: 0   Category :ASP.Net

[sub-titled: array.length is working correctly, but Nick has almost certainly done something stupid.] 

This is probably obvious, but has got me mystified.  I have an array which is being created like this:

var TempPoints = $get('<%=PointList.ClientID%>').value;
PointsList = eval(TempPoints);

The field coming in from the server is formatted like this:

[[1,2], [3,4], [5,6], ......... [99, 100]]

So, after the eval has done its work, PointsList is an array of objects, each of which is an array containing two numbers.  If I then do a PointsList.length, I would expect to see the number of elements in the array.  I then of course need to remember that the array is zero based and that the last element is (PointsList.length - 1).  Well, so I would have thought!

In fact, the length seems to be reporting one more than it should, so the last element is actually (PointsList.length - 2).

That is borne out by what I can see in the Visual Studio debugger:

Visual Studio Screenshot

As you can see there, the array has elements 0 through 138 - but the length is reported as 140.

What am I missing?



View Complete Post

More Related Resource Links

Need Syntax To Make Results of LINQ Union Return Non-Generic Type



I have the below SQL which works just fine:

SELECT     Message, CreateDate, AccountId, AlertTypeId
FROM       dbo.Alerts
SELECT     TOP (100) PERCENT Status, CreateDate, AccountId,
                          (SELECT     10 AS Expr1) AS AlertTypeId
FROM         dbo.StatusUpdates
WHERE AccountId = PassedInParameter

I have been going about trying to convert the above into a LINQ method and am having problems with return types.
As the above SQL illustrates, I am querying two distinct LINQ tables - Alerts and StatusUpdates -
and then attempting to perform a Union on them. In order to do the union in LINQ, I have to have agreeing types. So, I
am using "var" to make the results of "alerts" and "updates" generic before the union.  

public IList GetStatusUpdatesAsAlertsByAccountId<T>(Int32 accountId)
            using (WorkbookDataContext dc = _conn.GetCont

Invalid length for a Base-64 char array for my coding in ASP.net C#. How to solve it ?


Hi Friends ,

I have done encrypted password and decode but i got error  like  this  " Invalid length for a Base-64 char array" .

Pls help . Thanks


psswd = txtPassword.Text;

pwed = base64Decode(psswd);

public string base64Decode(string sData)
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(sData);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char); return result;

Function to return number


I am trying to create a function that  return the number part within / / from a url if exist:

For exmple:

http://www.mydomain.com/Mobile_Exec/1234/Orange_revamps_business_website.aspx SHOULD RETURN "\1234\"

http://www.mydomain.com/News/Orange_revamps_business_website.aspx    SHOULD RETURN "\\"

http://www.mydomain.com/News/Features/627362/Orange_revamps_business_website.aspx SHOULD RETURN "\627362\"

I prefer if possible to use regular expression. Any help would be really appreciated.

How to Pass higher Length of Byte Array to the remoting method

Dear all,I am using a windows application and the businness logic is present in the remote server.Once particular method takes bytearray as input parameter...Whenever the method call is made the function returns value .This is limited for the particular bytearray length. (4109228 bytes).If the length of bytearray crosses 4109228 bytes.I am getting an error that "input stream is not valid binary format".How to Pass higher Length of Byte Array to the remoting method... Greater than 4 MB?I believe something is missing in web.config or app.config...?What could be the issue...? Any sugesstions are welcome....ThanksRavikumar

Scalar Function Variable length return value

Would like to write a Scalar Function that returns a variable length string of spaces. Length being determined by an input parameter (int) Maybe I am missing the obvious but it seems impossible because you have to declare the size  of the varchar return variable I know there is a performance hit using scalar functions but we are generating a view that emulates an old fixed file format with lots of unused fields. So it will make the resultant view readable. So I am looking to do select goodfield1,fnSpace(5) as Unusedfield1,goodfield2,fnSpace(10)... from MyView thanks Bob

MDX problem: Return the number of days in a given selection/range

I've had this problem for a couple of days and found some "solutions" online. However, none of them worked. The goal is to calculate Inventory Turnover, but the problem is I can't seem to return the current number of days in the selection. The solution I found was: Count(Descendants([Date].[Date Hierachy], [Date].[Date Hierachy].[Date])) Which returned this: http://www.jandd.be/images/q_return.jpg However, I just want it to return the number of days that are in the selection, so the number of days between (incl) 22/08 and 25/09. This is a screenshot of my datedim, if it helps: http://www.jandd.be/images/q_datedim.jpg I can imagine this could be real simple or some setting that I didn't find on the dimensions, but it would be really appreciated if I could find a solution like this...

How to make an array of class objects in Visual Basic

How can I make an array of objects in VB.net. Here is the requirement.Basically I have a class named hotel. I need to dynamically add customersto the hotel class using the Customer class. So basically if in the Hotelclass I can have an array of Customer objects that would be great. How can I do this in VB .net ? Public Class Hotel  ' I need an array of Customer objects. objCustomers End Class   Public Class Customer Private custId As Integer Private custName As String Private custAddress As String Private custCity As StringEnd Class Pseudo code:  Dim Hilton As Hotel = new Hotel()   Hilton.objCustomers(5) ' Declare an array of 5 customer objects   Hilton.objCustomers(0).CustId=1  Hilton.objCustomers(0).CustName="JoJo Smith"  Hilton.objCustomers(0).custAddress="122 Emory Lane"  Hilton.custCity="Merry More"  .  .  .  Hilton.objCustomers(4).CustId=1  Hilton.objCustomers(4).CustName="Ice Baby"  Hilton.objCustomers(4).custAddress="66 Domino Drive"  Hilton.custCity="Miami"    End While

Incorrect number of users reported in SharePoint Usage Logs

* See last post - issue appears related to KB 969231 *   It seems SharePoint 2007 usage logging with anonymous access worked in IIS6 but not IIS7. Is there a way to fix it?   Background: The SharePoint Usage logging was working fine (approximately 20,000 hits per day) until the upgrade to a new IIS7 environment. The configuration in both environments is very similar (both Anonymous Access and Windows Authentication are enabled) however the new environment is only showing 600 hits per day.   This forum response from Cornelius J. van Dyk [MVP] suggests that Usage analysis/logging with Anonymous Access doesn't work, however it does work in our old IIS6 environment (a dash "-" is just shown in the usage logs which suggests an anonymous user): http://www.eggheadcafe.com/software/aspnet/29823445/sharepoint-doubt-is-there-any-way-to-find-out-how-many-users-have-logged-in-to-the-sharepoint-site.aspx   So I've concluded it's differences in IIS6/IIS7 authentication. Reading articles on the differences (e.g.  single auth pipline instead of two-stage) doesn't highlight any obvious reasons why this wouldn't work.   Any help would be greatly appreciated.   Thanks,   Peter

how to query return all data in Array Object ,Collection Object

how to query return all data in Array Object ,Hash Table ,And DataTable dataRowSelect * From Doc a

Make my WCF service return json

Iam trying to make my wcf serivce method to return JASON-object, but it dosen't work, when I open in a webbrowser it shows xml. How can I make this method to return json.I have inserted [WebGet(ResponseFormat = WebMessageFormat.Json)],,,, but it didn't help[WebGet(ResponseFormat = WebMessageFormat.Json)] protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems() { // TODO: Change the sample implementation here if (items.Count == 0) { items.Add("A", new SampleItem() { Value = "A" }); items.Add("B", new SampleItem() { Value = "B" }); items.Add("C", new SampleItem() { Value = "C" }); } return this.items; }[WebGet(ResponseFormat = WebMessageFormat.Json)]         protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()         {             // TODO: Change the sample implementation here             if (items.Count == 0)             {                 items.Add("A", new SampleItem() { Value = "A" });  &nb

fixed length array in CodeTypeReference?

I am trying to generate a fixed length array: e.g.: private object[5] _values;   I can generate member fine without the size but would prefer to have the length set at generation time.

Return an array to to jquery


Here's the problem I'm using the Jquery.ajax to call the [WebMethod].  I want to return some sort of array that I can use on the ajax side.  Are there any examples in doing this???  In addition can I return DataSets?



url: "Default.aspx/SeedCalendar",
data: "{'month': '" + month + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",

success: function(msg) {
$("#Result").text(msg[0]);  //first element in the array
error: function(e){ 
alert("error:" + e); 



public static string[] SeedCalendar(string month) 

string[] tseed = { "one", "two", "three" }; 

return tseed; 




MVC - Return Array Json

  function SaveDataToArray1(VungNguyenLieu, DienTich,LoaiGiong,
                                 SanLuong, TGXuongGiong, TGThuHoach) 
            var arr = new Array(arrData.length,
                                VungNguyenLieu, DienTich,LoaiGiong,
                                 SanLuong, TGXuongGiong, TGThuHoach);

        function ReloadGrid1() {
            $('#tbNoiDung tbody').html("");
            for (i = 0; i < arrData1.length; i++) {
                var tbRow = "<tr>";
                tbRow += "<td align=\"center\">" + (i + 1) + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][1] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][2] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][3] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][4] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][5] + "</td>";
                tbRow += "<td align=\"center\"

incorrect page number in footer


We have a 200+ page document with 33 sections (many created due to two columns of text and tables within the document). In addition, we are editing between Mac and PC. We want to keep the same footer throughout. They are finally all linked to the previous, except for the last section which begins on page 184. We have looked and looked (in draft mode, formatting codes on) trying to determine why the page numbering reverts back to 1 for that section, but can find nothing. The other part of the footer is fine, but the page numbering should start on 184. When we try to manually change the page format, the entire previous section changes. We are at wits end on this one. I tried copying and pasting the entire document to another document and the same thing happens.


Invalid length for a Base-64 char array - how do I check the length?????


Invalid length for a Base-64 char array

I am encrypting and decrypting my querystring. I need a way of checking the querystrings length before I decrypt it. When I mess with the querystring, shorten it for example, my decryption method fails. Can somebody help me with the if statement please to check the length of the urlDecode string??????

public static string Decrypt(string inputText)      {          if (!String.IsNullOrEmpty(inputText))

How to make number of columns of Gridview depends on a textbox value?


I have a Gridview with 12 columns, Jan, Feb...Dec.
I have a textbox value that could be 1, 2,...12

I want if textbox value is 7, then column Aug-Dec in Gridview is editable when in update mode and the column in Jan-Jul is not updatable (eg make it label instead of textbox).

How can I do this ?


How do I make it so when I user pressing return, it goes to the next line in a textbox?

I've got a textbox control on a WPF 4.0 app I've written.  This control allows for multiple lines, and that works fine.  However, my users like to be able to type something, hit the enter/return key which they're used to having it go to the next line in the textbox, where they then continue typing whatever it is they want to type.  Well, it's not doing that.  How do I make it do that?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend