Sunday, May 15, 2011

MVC3 Razor View Engine

People who are facinated using MVC2 here is some thing interesting feature i would like to share "Razor Engine" in MVC3.
ASP.NET MVC 3 ships with a new view-engine option called “Razor” (in addition to continuing to support/enhance the existing .aspx view engine.

Reason for Raqzor Engine in MVC3.
ASP.NET MVC always supported the concept of “view engines” – which are the pluggable modules that implement different template syntax options. The “default” view engine for ASP.NET MVC today uses the same .aspx/.ascx/.master file templates as ASP.NET Web Forms. Other popular ASP.NET MVC view engines used today include Spark and NHaml.

You can have Razor view engine in drop view engine dropdown when you create a view in mvc3.










You denote the start of a code block with Razor using a @ character. Unlike code nuggets, Razor does not require you to explicitly close the code-block:

Layout.cshtml” layout-page that will define the common layout UI we want across our site. The “RenderBody()” method indicates where view templates that are based on this master layout file should “fill in” the body content:

Master pages are a part of the ASPX WebForms view engine, not the MVC framework so Razor cannot interoperate with it.

For more details visite ScottGu's Blog :
http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx

Tuesday, April 26, 2011

Implementing BING Maps Ajax control in ASP.net

I implemented BING maps Ajax control 6.3 for our corporate web site, and i would like to share here on my blog.


Basic thing here is i have used ajax control to give good user experience where zoom-In and zoom-Out are very easy with no server post backs.

I implemented Bing maps using Location data  we have in our DB including Latitude and Longittude values, using which i  placed cluster points on Bing Maps.

Below are breif steps, need anything more i can help
To use Bing maps ajax control place the below script tag in ASPpage or if you have master page the place in it.


1.First retreive Data from DB it should have latitude and longitude Data so that we point exact locations on Map.
To user bing maps ajax control place this script tag src in your aspx page html or master page
 src=https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3

2.Pass Latitude and longidtude as Arrays to the Javascript function as i did in below, use this code in your code behind file in a method.StringBuilder sb = new StringBuilder("var lats = new Array(); var longs = new Array();var LocNames = new Array(); var Address = new Array();");



sb.AppendLine();for (int i = 0; i < dtArrayLocations.Rows.Count; i++)
{
if ((dtArrayLocations.Rows[i]["Latitude"] != System.DBNull.Value) && (dtArrayLocations.Rows[i]["Longitude"] != System.DBNull.Value))
{
sb.AppendFormat("lats[{0}]={1};longs[{0}]={2};LocNames[{0}]='{3}';Address[{0}]='{4}';", i, dtArrayLocations.Rows[i]["Latitude"], dtArrayLocations.Rows[i]["Longitude"], dtArrayLocations.Rows[i]["LOCATION_DESCRIPTOR"].ToString(), dtArrayLocations.Rows[i]["ADDRESS"].ToString().Replace("\n", "") + "," + dtArrayLocations.Rows[i]["CITY"].ToString().Trim() + "," + dtArrayLocations.Rows[i]["STATE_CODE"].ToString().Trim() + "," + dtArrayLocations.Rows[i]["ZIP"].ToString().Trim() + "
" + FormatPhoneNumbers(dtArrayLocations.Rows[i]["PHONE1"].ToString().Trim()) + "
" + dtArrayLocations.Rows[i]["FAX"].ToString());

}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "PointArrays", sb.ToString(), true);
Page.Form.Attributes.Add("onload", "LoadPushPins();");

3. Within Javscript LoadMap using the aobe latitude,longitude values. as below
  myMap = new VEMap('mapDiv');
function LoadPushPins() {
if (lats != null) {
for (var i = 0; i < lats.length; i++) {
var pp = new VEShape(VEShapeType.Pushpin, new VELatLong(lats[i], longs[i]));
myMap.SetCenterAndZoom(new VELatLong(lats[i], longs[i]), 13);
// Create a pin at that location
var desc = "");
pp.SetDescription(desc);
myMap.AddShape(pp);
myMap.Resize()
}}
function Cluster() {
searchShapeLayer.SetClusteringConfiguration(VEClusteringType.Grid);
}


The idea of sharing this is to give basic idea to implement BING Maps with DB i had tough times in exploring this. If you need any more details leave comment i can get back to you.

Enjoy :)


Monday, December 6, 2010

AjaxControlToolKit-Tab Panel

These days i got a chance to work on real cool stuff using AJAX control Toolkit, i used Tab Panel,CollapsiblePanelExtender and also Bing Maps AJAX Control, Version6.3. .

You will be seeing some more stuff on my blog in comming weeks on these controls, for now i would like to share something about TabPanel.

Below code will display list of data in one tab and Map on other Tab, based on search performed in previous page.

For this i used Design time to work with Tabcontainer and 2 Tab panels, check the below sample, if you need any more details leave a comment
<asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" enablepagemethods="true">
</asp:toolkitscriptmanager>
<asp:tabcontainer id="TabContainer1" runat="server" activetabindex="1" cssclass="ajax__tab_xp"
autopostback="true" onactivetabchanged="TabContainer1_ActiveTabChanged" width="100%"
onclientactivetabchanged="LoadMap">
<asp:TabPanel runat="server" HeaderText="List View" ID="tbpanleList" TabIndex="0">
<HeaderTemplate>
List View
</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<!--Display the results here using Grid/Table-->
</ContentTemplate>
<Triggers>
<!--- Place any events for implementing callback using update panle defined above , this update panel will be for this Tab Panel--->
</Triggers>
</asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="tbpanleMapView" HeaderText="Map View" runat="server" TabIndex="1">
<HeaderTemplate>
Map View
</HeaderTemplate>
<ContentTemplate>
<div style="position: relative; width: 700px; height: 450px;" id="mapDiv" " />
</div>
<br />
</ContentTemplate>
</asp:TabPanel>
</asp:tabcontainer>

:)

Friday, September 3, 2010

Parse XML and store to DataTable

Parse the xml results and store data to Datatable.Below a Method will Display Data in Lables using result DataTable when URL is passed.

public void DisplaySearchResults(string URL)
{
XmlDocument myXMLDocument = null;
DataRow drDetails;
string ID;
string Title;
string Desc;
Label lblErrorMessage= new Label();

DataTable dtSearchResults = new DataTable();
try
{
myXMLDocument = new XmlDocument();
myXMLDocument.Load(URL);
XmlNodeList objNodeList = myXMLDocument.SelectNodes("Root/Child1/);
DataColumn dcID = new DataColumn("ID", typeof(string));
DataColumn dcTitle = new DataColumn("Title", typeof(string));
DataColumn dcDesc= new DataColumn("Description", typeof(string));
dtSearchResults.Columns.Add(dcID);
dtSearchResults.Columns.Add(dcTitle);
dtSearchResults.Columns.Add(dcDesc);
foreach (XmlNode hitNode in objNodeList)
{

drDetails = dtSearchResults.NewRow();
ID = hitNode.SelectSingleNode("FIELD[@NAME='id']").InnerText;
drDetails["ID"] = ID;


Title = hitNode.SelectSingleNode("FIELD[@NAME='title']").InnerText;
drDetails["Title"] = Title;

Desc = hitNode.SelectSingleNode("FIELD[@NAME='desc']").InnerText;
drDetails["Description"] = Desc;

dtSearchResults.Rows.Add(drDetails);
dtSearchResults.AcceptChanges();

}

TableRow row;
TableCell cell1;
TableRow rowbody;
TableCell cell2;
Label lblTitle;
Label lblbodytext;

lblErrorMessage.Text = "";
if (dtSearchResults.Rows.Count > 0)
{
for (int i = 0; i < dtSearchResults.Rows.Count; i++)
{
row = new TableRow();
rowbody = new TableRow();
cell1 = new TableCell();
cell2 = new TableCell();

lblTitle = new Label();

lblTitle.Text = dtSearchResults.Rows[i]["Title"].ToString();
cell1.Controls.Add(lblTitle);
lblbodytext = new Label();
lblbodytext.Text = dtSearchResults.Rows[i]["Description"].ToString();

cell2.Controls.Add(lblbodytext);
row.Cells.Add(cell1);
rowbody.Cells.Add(cell2);
tblsearchresults.Rows.Add(row);
tblsearchresults.Rows.Add(rowbody);

}
}
else
{
lblErrorMessage.Text = "No search results were found. Please try again";

}

Define a asp table in your ASPX page like below


This is basic solution, you can also do paging of xml result set like Google or Bing.

If this solution helped anyone Please leave a comment.

Enjoy Coding :)

Tuesday, August 10, 2010

SharePoint Server 2007 vs. 2010 Feature Comparison Matrix

Microsoft SharePoint Server 2010- You may have noticed that the 'Office' part of the name has dropped out. The reason being is that the “Office” brand will no longer include Server side components (such as SharePoint).

To know more about sharepoint 2010 check the below article that gives a comparison matrix between MOSS2007 and Sharepoint 2010.

http://www.khamis.net/blog/Lists/Posts/Post.aspx?ID=4

Have fun

Free videos on sharepoint2010(Evaluation only)

Some Free videos on sharepoint2010(Evaluation only not full videos)

http://www.point8020.com/SharePointEndUserTraining.aspx.

Getting Started with SharePoint Server 2010 for IT Pros-http://technet.microsoft.com/en-us/sharepoint/ee518660.aspx

Hope it helps for Know-How of SharePoint 2010.

Have Fun

Monday, May 3, 2010

Display Breadcrumbs Trail in a simple way

Here is very crisp and short way of implementing Breadcrumb for ASP.net Website.

Create a Link for Home,link for primary link and if you have secondary link and a label to display page user enterd.
HyperlinkHome>[hyperlink1]>>[hyperlink2]>[lblPageName].

Create 3 properties for Primarylink1 and secondarylink(if any) and for label.
public string primarylinkpagecode{ get; set; }
public string primarylinkpageText { get; set; }
public string SecondarylinkpagecodeCode { get; set; }
public string SecondarylinkpageText { get; set; }
public string PageTitle { get; set; }
The page's which are going to utilize this breadcrumb should pass the respective values to the above properties.

Ex:
Home>Cameras>Sony>Sony cybershot
UCBreadCrum.Link1Code = Cameras;
UCBreadCrum.LinkText = Cameras;
UCBreadCrum.Link2Code = Sony;
UCBreadCrum.Link2Text = Sony;
UCBreadCrum.Title = Sony Cybershot;

If you have any static pages and want to implement breadcrumbs below are value and properites to be passed.

1.Breadcrumb for a static
Home>Company


Link2Code="static"
Link2Text="Company"
2.If you want to display breadcrumb trial as
Home>Company>About us the

Link2Code="static"
Link2Text="Company"
Title="About uS"
And Keep the URL for Company in web.cofig and make sure the Like2TExt(Company) and web.config key name should be same(Even same case) .



below sample code for Displaying Breadcrumb for static page.

if (Link2Code == "static")
{
lbl1.Visible = true;
lbl2.Visible = false;
lbl3.Visible = true;
hlHome.Visible = true;
hlHome.Text = "Home";
hlHome.NavigateUrl = "../Forms/Index.aspx";
hlLink2.Text = " " + Linke2Text + " ";
hlLink2.Visible = true;
lblName.Text = " " + Title;
lblName.Visible = true;
hlLink2.NavigateUrl = System.Configuration.ConfigurationManager.AppSettings[Linke2Text];
}


If you need more information on implementing breadcrumb for dynamic content pages like any detail pages ,let me know.

Happy coding