Monday, January 24, 2011

Unable to connect to asp.net development server


I got this error after updating Microsoft Visual Studio 2008 Service Pack 1 (which took much longer than expected - close to two hours):

WebDev.WebServer.exe has stopped working
Unable to connect to the ASP.NET Development Server

As usual, this appeared to be a problem many people had, under many different scenarios, with many different solutions. The following solution is the solution that worked for me:

Delete the web project from the solution, rename the folder where the website is stored and then re-add the project to the solution as an existing website.

This is fine on my local laptop, but would probably be a bit more disconcerting in Visual Source Safe.

So my best guess is Visual Studio stores information about a web site somewhere.  If you don't perform the folder rename, when you add the web site back in you'll see the original, dynamic port settings.  It appears renaming forces a new port.

I don't know where this information is stored.  I can't seem to find anything in the registry, and deleting the temporary asp.net files didn't have any affect.

Although renaming the folder worked, I also did this:

The host file at %\Windows\System32\drivers\etc\hosts may have an incorrect entry. This line...

::1 localhost

was changed to...

:::1 localhost

That's three colons - not two.

I didn't experiment any further and have just moved on.


Sunday, January 2, 2011

Set Class From Javascript


//change the tab class style
var browser=navigator.appName;
var classtyp;
if(browser=='Microsoft Internet Explorer')
{
classtyp = "className";
}
else
{
classtyp = "class";
}

if (val=='new')
{
document.getElementById("liUpcoming").setAttribute(classtyp, "selectednews");
document.getElementById("liPast").setAttribute(classtyp, "");
}

Friday, December 31, 2010

Finds a Control recursively in Asp.net

On one of my project i need to Find the controls till get the result control so i have built the code like this...

Below is Method Definition :

/// <summary>
/// Finds a Control recursively. Note finds the first match and exists
/// </summary>
/// <param name="ContainerCtl"></param>
/// <param name="IdToFind"></param>
/// <returns></returns>
public static Control FindControlRecursive(Control Root, string Id)
{
string str =string.Empty;
if (Root.ID == Id)
return Root;
foreach (Control Ctl in Root.Controls)
{
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
{
switch (Id)
{
case "hdnProductId":
staticProductId = ((System.Web.UI.HtmlControls.HtmlInputHidden)FoundCtl).Value;
break;
case "hdnProductName":
staticProductName = ((System.Web.UI.HtmlControls.HtmlInputHidden)FoundCtl).Value;
break;
}
break;
}
}
return null;
}

Below is Method Definition in GIF Format :


Below is how to call that method:-

FindControlRecursive(this.Page.Master, "hdnProductId");
FindControlRecursive(this.Page.Master, "hdnProductName");

Below is how to call that method in Gif Format:-

Wednesday, December 29, 2010

Convert month number to month name in sql

In this blog I will explain you how to convert month number to month name in sql. To explain it I have used

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ).Below is the code snippet:


DECLARE @MONTHNUMBER INT

SET @MONTHNUMBER=1

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ) AS [MONTHNAME]

-OUTPUT


MONTHNAME

------------------------------

January

DECLARE @MONTHNUMBER INT


SET @MONTHNUMBER=12

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ) AS [MONTHNAME]

--OUTPUT


MONTHNAME

------------------------------

December



2 ).Below is the code snippet:

SELECT CONVERT(VARCHAR(3), DATENAME(MM, CreatedDate_ColumnName), 100)

Monday, December 27, 2010

Clear Controls in Asp.Net

Main Function to Read All controls in do action :-



Call the Method by this way. here in my first line this is multiview id i want to clear all controls under multiview, and on the second one all controls available in the page..

Tuesday, December 21, 2010

Distinct in XSLT

This Example Use for sort the year in xslt for this we need to get unique year id i.e. in xslt generic-id bases we can trace unique here example below:----

Test XML Feed Here:--
<state id="26179" status="Approved" golive="Wednesday, December 22, 2010" created="Wednesday, December 22, 2010" golivetime="9:00:00 AM" createdtime="9:42:11 AM" creator="Indigo Consulting">
<elements state="26179" parent="0">
<element id="97398" position="1" type="Custom">
<content>
<day>6</day>
<month>February</month>
<year>1996</year>
<title>testing first new2</title>
<historyimage />
</content>
</element>
<element id="97399" position="1" type="Custom">
<content>
<day>4</day>
<month>February</month>
<year>1996</year>
<title>testing first similar new2</title>
<historyimage />
</content>
</element>
<element id="97403" position="1" type="Custom">
<content>
<day>4</day>
<month>October</month>
<year>2012</year>
<title>testing first new5</title>
<historyimage />
</content>
</element>
</elements>
</state>

XSL Content:-
-----------
<xsl:key name="distinctYear" match="state/elements/element[@type = 'Custom']/content" use="./year"></xsl:key>

---Under Applytemplate section--------------
<xsl:for-each select="state/elements/element[@type='Custom']/content[generate-id(key('distinctYear', ./year)) = generate-id()]">
<xsl:sort select="year"/>
<li>
<a href="#{year}">
<xsl:value-of select="year" />
</a>
</li>
</xsl:for-each>

Sunday, December 19, 2010

ASP.NET 2.0 MasterPages and FindControl()

Argh. I'm going through an older application and replacing a somewhat complex scheme of user control templating with Master Pages today. For the most part this has been going real well until I hit a page that that relies on page inheritance where there's a common page base class that needs to have access to the controls on the page.

ASP.NET has never made this exactly easy, because the base class doesn't allow you access to the controls from the lower level as ASP.NET adds the properties higher up in the hierarchy. In the past I've been working around this by adding properties for the controls to the base class and then overriding these properties, but in ASP.NET 2.0 the control definitions are auto-generate with no chance to override the control definitions. The only workaround has been using FindControl() and dynamically retrieve the control definitions.

And this is where things get a bit tricky with MasterPages. The problem is that when you use MasterPages the page hierarchy drastically changes. Where a simple this.FindControl() used to give you a control instance you now have to drill into the container hierarchy pretty deeply just to get to the content container.

protected Label lblError = null;

protected DataGrid dgItemList = null;

protected void AssignControls()

{

this.lblError = this.FindControl("lblError") as Label;

this.dgItemList = this.FindControl("dgItemList") as DataGrid;

}

you now have to drill into the containership with code like this:

protected void AssignControls()

{

this.lblError = this.Master.FindControl("Content").FindControl("lblError") as Label;

this.dgItemList = this.Master.FindControl("Content").FindControl("dgItemList") as DataGrid;

}
Image Is below:-


This isn't so bad, except when you're trying to figure out how to get to your controls.

It really seems lame that Microsoft hasn't added a recursive FindControl() method to the Control class that drills into child containers. While this certainly isn't optimal in terms of performance it sure would make life a lot easier in a lot of situations, and this surely is one of them.

Not exactly rocket science to create a method that does this:

/// <summary>
/// Finds a Control recursively. Note finds the first match and exists
/// </summary>
/// <param name="ContainerCtl"></param>
/// <param name="IdToFind"></param>
/// <returns></returns>

public static Control FindControlRecursive(Control Root, string Id)

{

if (Root.ID == Id)

return Root;

foreach (Control Ctl in Root.Controls)

{

Control FoundCtl = FindControlRecursive(Ctl, Id);

if (FoundCtl != null)

return FoundCtl;

}

return null;

}

with this the code becomes:

/// <summary>
/// Assigns controls from the subclassed control to this instance so
/// we always can access the controls in our base class.
/// </summary>

protected void AssignControls()

{

this.lblError = wwWebUtils.FindControlRecursive(this.Master,"lblError") as Label;

this.dgItemList = wwWebUtils.FindControlRecursive(this.Master, "dgItemList") as DataGrid;

}


Image Is below:-




Although this is easier, I suspect it's better to do the explicit thing if that option is available to you as it probably has better performance. Also I suspect Microsoft didn't include this sort of a function in ASP.NET natively because there's potential ambiguity here – there could be more than one control Id that matches a name.