Thursday, February 11, 2016

Redirect website into IFrame.

Hello,


Below is code to redirect website url to IFrame.


Add IFrame in webpage.



<iframe id="IframeID" runat="server" height="100" width="100"></iframe>

Here note that we have frame with runat="server" attribute. so we can use from code behind.



IframeID.Attributes.Add("src", "http://dotnet-magic.blogspot.in");


Enjoy!!!!!

Monday, February 8, 2016

Session state has created a session id, but cannot save it because the response was already flushed by the application.

This happens because sometimes (depending on the web.config configuration) the SessionID is not set in the cookie when Session_Start event executes in the global asax.

You encounter this error because at somepoint in the pagelifecycle a variable is set in the session. after the request ends, ASP.NET tries to set the SessionID too, but if the Request was flused 
(eg. this can be done by Response.Write or AJAX itself flushes the response) this exception will be thrown.



Add following code in the global.asax file:




      void Session_Start(object sender, EventArgs e) 
      {
          string sessionId = Session.SessionID;
 //This code run when new session is started.
      }

Saturday, February 6, 2016

Remove last semicolon from a string.

Remove last semicolon,comma from a string.

Hello,

Sometimes we need to remove last comma,semicolumn extra from a
string.

Below is simple way to do this.

text = text.TrimEnd(',');

This is better way instead of Substring option.




Alter Message box from code Behind in C# Asp.Net

Alter Message Box from Code Behind


Response.Write(@"<script language='javascript'>alert('The following errors have occurred:" + ErrorDesc + ".');</script>");

Now if you want error message in secondLine.
here the trick.

Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + ErrorDesc + " .');</script>");

or you can double escape the \n by doing 

Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \\n" + ErrorDesc + " .');</script>");

Unable to copy file "obj\Debug\Project.exe" to "bin\Debug\Project.exe". The process cannot access the file "bin\Debug\Project.exe" because it is being used by another process.

Problem
Unable to copy file "obj\Debug\*.exe" to "bin\Debug\*.exe". The process cannot access the file "bin\Debug\*.exe" because it is being used by another process.


The reason behind this error is Visual Studio locks the file.

if you close your solution and reopen it your project build successfully without error.
But this is not a preferable solution  all the time.

Below is one suggestion to resolve this problem

When the problem occurs, just change the building configuration at the top (if in “Release” to “Debug” and vice versa), build and then change back to previous configuration and build again.

Hope this will help you.