In the bad old days of desktop applications, every form object in the world had a Dirty property that let you easily check to see if the user had made any changes to the data on the form. It’s almost as easy with client-side code running in the Web browser, provided you use jQuery. This line finds every input tag and ties the tag’s change event to a JavaScript function called flagChanges:
I would like to loop through following collection of authors and for each author retrieve its first and last name and put them in a variable strFirst and strLast?
We’ll use XmlDocument class to parse this XML fragment;
using System;
using System.Xml;
public class XMLApp
{
public void YourMethod(String strFirst, String strLast)
{
// Do something with strFirst and strLast.
// ...
Console.WriteLine("{0}, {1}", strLast, strFirst);
}
public void ProcessXML(String xmlText)
{
XmlDocument _doc = new XmlDocument();
_doc.LoadXml(xmlText);
// alternately, _doc.Load( _strFilename); to read from a file.
XmlNodeList _fnames = _doc.GetElementsByTagName("FirstName");
XmlNodeList _lnames = _doc.GetElementsByTagName("LastName");
// I'm assuming every FirstName has a LastName in this example, your requirements may vary. //
for (int _i = 0; _i < _fnames.Count; ++_i)
{
YourMethod(_fnames[_i].InnerText,
_lnames[_i].InnerText);
}
public static void Main(String[] args)
{
XMLApp _app = new XMLApp();
// Passing XML text as a String, you can also use the
// XMLDocument::Load( ) method to read the XML from a file.
//
_app.ProcessXML(@" <Authors>
<Author>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Author>
<Author>
<FirstName>Shahzad</FirstName>
<LastName>Khan</LastName>
</Author>
</Authors> ");
}
}// end XMLApp
}
2 column layouts are rather popular on the web, and there are 1,001 ways to make them work. The approach you choose really depends on the type of content you have, and how you want images and backgrounds to work. What I’ll show is the Razor _Layout and CSS to achieve the following look:
The Razor _Layout file can rely on partial views to handle each of the primary sections: top, navigation, sidebar, and footer. RenderBody will produce the primary content area.
A quick note on Html.Partial. If any sections, like the sidebar and navigation sections, require some logic or model information to build their piece of the UI, then use Html.Action instead of Html.Partial. Html.Action allows you to setup a little sub-request inside the current request and allow a controller action to build a model and select a view.
The CSS coming up assumes each partial view will render inside an element with an id matching it’s purpose (so the _top view renders a div with an id of top).
The trick is to use absolute positioning on the sidebar content, which is possible because we know the exact amount of space taken by the 2 sections at the top of the page, and we know the exact width of the content area (it is set explicitly in the CSS). You’ll probably want to give the body more space than the 300px given in the sample above (which was constrained so the screenshot would fit on this page).