Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Posts Tagged ‘ASP.NET

element style cannot be nested in div–ASP.NET Masterpage

leave a comment »

 

You can create another Content Place Holder in master page

<head>
<asp:ContentPlaceHolder ID="Head" runat="server">
</asp:ContentPlaceHolder>
</head>

Then in pages, you need to put two content place holder and put your stylesheet and script in Head place holder.

Simple!!!

Written by Manish

December 4, 2010 at 2:42 pm

Add Custom Message to ValidationSummary in ASP.NET

leave a comment »

 

Following is the code you can write to put the message in validation summary while doing validation on button or on another event.

CustomValidator val = new CustomValidator();
val.IsValid = false;
val.ErrorMessage = "Custom error message to add to the ValidationSummary";
this.Page.Validators.Add(val);

Written by Manish

November 24, 2010 at 6:20 pm

Literal content is not allowed within skin file

leave a comment »

We have following errors in our project

Literal content (‘<gv:TwoHeadedGridView SkinID="gv"  EmptyDataText="No Record(s) Found."  AllowPaging="true" PageSize="10" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">  </gv:TwoHeadedGridView>’) is not allowed within a ‘skin file’.

The problem here is, we missed runat=server attribute. Simple 🙂

[tweetmeme only_single=”false”]

Written by Manish

October 5, 2010 at 2:45 pm

Threading in ASP.NET

leave a comment »

You can do the same method which we can do in form based application. You need to be sure about the logic you are doing in the Thread.

Suppose you are accessing, Session in the thread and if thread is taking longer while the page code’s Response ended. Then you have problem as when response is ended the session variable of request is cleared.

So if you are accessing Request.Session , it will show null value after response is added.

You might call thread on page.init and in page load, you can call Join to wait for thread to complete and go ahead.

Below is sample code: I have passed context as thread’s parameter. It will be used fully as I used Join of thread. If I do not use Join then some of the variables is not available in context parameter. The conclusion is we can use thread same way but we need to be sure of page parameters/context parameters which we are passing to thread. That’s it!!!

protected void Page_Load(object sender, EventArgs e)
{
        Thread t = new Thread(new ParameterizedThreadStart(ref CallAnalyticsFunction));
        t.Start(this.Context);
        
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetAllowResponseInBrowserHistory(false);

        Response.ContentType = "image/gif";
        Response.AppendHeader("Content-Length", _imgbytes.Length.ToString());
        Response.Cache.SetLastModified(DateTime.Now);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.BinaryWrite(_imgbytes);
        Response.Flush();

        t.Join();
}
[tweetmeme only_single=”false”]

Written by Manish

October 3, 2010 at 4:06 pm

Server Tags <%…%>

leave a comment »

<% %> An embedded code block is server code that executes during the page’s render phase. The code in the block can execute programming statements and call functions in the current page class. http://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx

<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx

<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx

<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx

<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx

<%– –%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx

Written by Manish

November 10, 2009 at 11:57 pm

Posted in .NET, .NET 3.0

Tagged with , ,