.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

Javascript issue - read from xml

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

I'd like to read data from my xml, but I always get a nasty "xmlDoc.getElementsByTagName(...).0' is null or not an object" error

I can make an alert with an entire xml, but the problem is i can't read it!?

Here is my JS code:

 <script type="text/javascript">
        function parseCommentXmlToHtml(xml, motivatorIndex) {

            function loadXMLString(xml) {
                if (window.DOMParser) {
                    parser = new DOMParser();
                    xmlDoc = parser.parseFromString(txt, "text/xml");
                else // Internet Explorer
                    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async = "false";
                    alert(xmlDoc.getElementsByTagName("images")[0].getAttribute("author_nick")); // ERROR
                return xmlDoc;



Here is my XML:


<images insert_date="2010-10-10T20:06:00" comment_text="afs" author_nick="Guest"/>

<images insert_date=&

View Complete Post

More Related Resource Links

JavaScript iframe resezing issue



I have an iframe that is supplied by another application, inside the iframe I have my .Net application. However, I am having sizing issues, where one minute that pages in the .Net fit the frame perfectly and the next minute they don't, with a vertical and horizontal scroll bars appearing. All the .Net Pages use a Master Page and I have also fixed the size of the pages, but with no luck. What I would was thinking if possible is to pass some javascript between the .Net application and the iframe which will make the pages and the iframe resize themselves. Has anyone done this before and have some code that I could use?

Check-out issue when opening a document from a document library when a read-only copy is open

We have an issue when a user has a read-only copy of a document from SharePoint open and then tries to check-out and edit another copy of the document (i.e. from the document library) the checked out copy is not connected to the web server. For the user it will look the same they will make edits, save and then close, but when they do so the document is not updated in SharePoint - it may be saved locally in their SP drafts, but the user will think that they have lost their version. We then get the checked out to another user error and you have to discard changes to get the document working again. Steps to reproduce this issue: * click on the name of a office doc on a Document Library * Make sure "Read Only" is selected and click "ok" * Minimize open document * click on the same file on the Document Library * Make sure "check out and edit" is selected and the "Use my local drafts folder" checkbox is ticked. Select OK. * Edit document and press save. Changes are never saved back in SharePoint, they are only on the local draft. We are using MOSS with SP2. Clients are on Office 2003 and 2007 Is this normal behaviour? Is there anything that can be done to prevent this from happening?

Viewstate issue when calling button click event from Javascript

I have a javascript that asks a confirmation on search click. If the user has made some changes to the data in grid (gridview) on click of Search, a confirmation is asked to Save or Continue Search. If Yes, Save the records by invoking Save click from javascript. If No, Search click is invoked. While Search click happens correctly, Save click results in an error which reads like this..  "Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. " I know the Viewstate is what causing the problem, where the control is not loaded but script is trying to invoke it's click event. Any help is appreciated. At the end of the day, all i need is to invoke Save click from javascript.   -- Viswanth VG  

read cookie in javascript


Hi i have set a cookie in c# code and made sure the HttpOnly = false, i need to read this in javascript but need some help.

i am trying the following...

//c# code
HttpCookie cookie = new HttpCookie("CompId", item.Id.ToString());
cookie.Expires = DateTime.Now.AddHours(1);
cookie.HttpOnly = false;

//js code

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
    return "";

function Test() {
var compId = getCookie('CompId');

javascript window.history.back() issue with Modal popup extender



I have a asp.net page that has a list of items. When one of the items from the list is clicked a details page is displayed. This details page has a link button to show a popup for history of the item. The details page also has a button with text 'Back'.  The back button has onclick event set to  "javascript:window.history.back();".

This back button works fine and goes back to the first page. However when the user is on the second page and opens the pop up by clicking on the link button, the back button stop working and displays Webpage has expired message.

Any help would be appreciated.




Read Excel file to datatable using javascript


I have an asp.net website. I have to upload data from an excel file on the client machine to sql server. I save the excel file on the server where webstie is hosted and try to read from that excel. But users dont have read permission on the server. So i need to read the excel on the client side using javascript and populate the datatable so that i can use that datatable in sql bulk copy to populate my sql tables. so how to read entire excel in javascript and populate to datatable

SQL & JavaScript - Apostrophe Issue, SELECT statement is not returning any results.



Any help would be great on this.

I have the following code within an .asp page in JavaScript:

function SDsitecalls1(Sitename)

end function

The function is called via the below:

 <td style="width: 114px" class="style65"><a href="/suppdesk/customercalls.asp?customer=BSFMAN&site=Our+Lady''s+R+C+Sports+College"><%=SDsitecalls1("Our Lady's R C Sports College - Hbev")%></a></td> 

When this is ran I do not receive any errors but the SELECT command doesn't return any results (Just a 0). I've tried a few different methods such as using the Parameter SiteName and Single/Double Apostrophes however I either receive an error or blank results.

The function works with all other names however the apostrophe seems to cause issues here. Is there a way to extract the data without editing the SQL?

Thanks very much for the help,


read and print sharepoint list information using javascript



i am working on a form right now, user's inputs will be stored in a sharepoint list. after user click submit, it will display a thankyou panel, and send a email to me showing user's input. on the thankyou panel, there is a button, if user click it, it will open a new window and display exactly the same thing in email, so that user can check if they input the right thing.

i did this part using javascript, the window.open method. and i wrote html code in it, using window.document.write method.

i wrote a read from sharepoint list function, i dont know if it is working, but my question is how can i call this function in javascript since it will be a client side programming.

my readfromlist code is here:

public void readFromList()
             SPSite oSiteCollection = SPContext.Current.Site;
             SPList oList = oSiteCollection.AllWebs["something"].Lists["somelist"];
             SPView oListView = oList.Views["All Items"];
             SPListItemCollection collectListItems = oList.GetItems(oListView);

             foreach (SPListItem oListItem in collectListItems)
                 txtFirstName.Text = SPEncode.HtmlEncode(oListItem["First Name"].ToString()) + "<BR>";

HyperLinkField Javascript DispEx: clicking link shows Read Only/Edit dialog


I have a web part that uses an SPGridView to display the documents that match previously selected criteria.

The user needs to see the 'Read Only / Edit' dialog that is displayed when a document is selected directly from the document library.

My research shows that I need to call the Javascript DispEx function somehow. How do I do this in the HyperLinkField setup? Can I somehow call it in the DataNavigateURLFormatString? This code is my latest attempt (which doesn't work). The 'onclick=' appears in the hyperlink.

 Dim hfTitle As New HyperLinkField()
            hfTitle.DataTextField = "name"
            hfTitle.DataNavigateUrlFields = URL
            hfTitle.DataNavigateUrlFormatString = _
"<a onclick=" & Chr(34) & "return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.2','0','SharePoint.OpenDocuments','','','','1','1','0','0x7fffffffffffffff')" & _
Chr(34) & "href={0}"

            hfTitle.HeaderText = "Name"

SQL CE 4.0 - able to overcome NLS indexes read only issue in 3.5?


Will SQL CE 4 overcome the current issue where if a database is created on one platform it needs to have the indexes changed the first time its opened on another platform.  My issue with this is not how long it takes the first time, more that I wish to have the database protected and read only at all times, in fact it may also reside on read only media.  I am accessing the database from a winforms application. 

If not does anyone know of a way to overcome this problem? I cant go back to v3.0 for other reasons


ScriptManager.RegisterStartupScript and dynamic javascript issue


Hi all,


On my project I have a WebUserControl (.ascx) inside a page (the ascx is added statically on the HTML of the page, not dynamically).


On the ascx, on Page_Load, I need to generate a dynamic javascript function, and at the end register it (I do this everytime the page loads, being or not a PostBack).


Something like this is created:


private string GetScript()


return "function doSomething(){}";



And what I do after this on Page_Load is:



What I'm facing is this:


I'm able to get this working ok on my machine (XP SP2 Pro, IIS 5.1, Framework 3.5) and on a test server (Server 2003 Web Edition, IIS 6, Framework 3.5).


But on a high availability environment (production server and environment, Server 2003 Web Edition, IIS6, Framework 3.5, the machines have the same machine.config, the web sites have the same web.config file) the first time the page/webusercontrol shows up this works fine. If I make a postback, the javascript does not work. No error is thrown, no exception, just there is

Read Image from excel file Issue


Hello every one.I'm trying to read images from an excel file using OleDbDataReader. My excel file has 6 columns of data, the first 5 are all text but the last is image. While I'm reading the record, It's doing fine on the first 5 columns but return me with a "blank" for the sixth column.

Here is my demonistration code:

  protected void btnImportExcelFile_Click(object sender, EventArgs e)

      string strConn;
      strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
      "Data Source=C:\\exceltest.xls;" +
      "Extended Properties=Excel 8.0;";
      OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM Sheet1$]", strConn);

      DataSet myDataSet = new DataSet();
      myCommand.Fill(myDataSet, "Sheet1");
      DataGrid1.DataSource = myDataSet.Tables["Sheet1"].DefaultView;


<asp:Button ID="btnImportExcel

* Read/connect my "DBConnectionString" from webconfig in JavaScript



Any one send me sample code, 

I have my ASPX.net + SQL 2008

I have "DBConnectionString" in my webconfig.

I want read/connect my "DBConnectionString" from webconfig, how to do that... ?


function getSubmit() {
		        var txtDivOpen;
		        var cn = new ActiveXObject("ADODB.Connection");
		        var strConn = '<%=ConfigurationManager.AppSettings["DBConnectionString"].ToString() %>';
		        var rs = new ActiveXObject("ADODB.Recordset");
		        var SQL = "select * from ENVDB_WASTE_COLLECTION";

		        rs.Open(SQL, cn);



ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

call JavaScript - jQuery code from ASP.NET Server-Side

jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side.

call JavaScript - jQuery code from ASP.NET Server-Side

jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side

Ajax Enabled Gridview using JavaScript in ASP.NET

Before explaining the article, I would like to thank all readers who read my article and voted for it. Your appreciation for my article gives me strength to write more good articles. Hope in future I will get your valuable comments and suggestions. Now I won't waste your time and come back to the topic. I have written this article on 'Ajax Enabled Gridview Using JavaScript in ASP.NET'. In this article, I will show you how to make a Gridview using a simple HTML table, JavaScript and XML HTTP for Ajax call without using any ASP.NET control.

Using Code
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