Monday, June 23, 2014

Date And Time in Master Page Using Java Script

<head runat="server">
<title>JavaScript display current time on webpage</title>
<script type="text/javascript">
function ShowCurrentTime() {
var dt = new Date();
document.getElementById("lblTime").innerHTML = dt.toLocaleTimeString();
window.setTimeout("ShowCurrentTime()", 1000); // Here 1000(milliseconds) means one 1 Sec  
}
</script>
</head>
<body onload="ShowCurrentTime()">
<form id="form1" runat="server">
<div>
JavaScript Display current time second by second.
<label id="lblTime" style=" font-weight:bold"></label>
</div>
</form>
</body>

</html>

What is CTS (Common Type System) ?

The common type system defines how types are declared, used, and managed in the runtime, and is also an important part of the runtime's support for cross-language integration. The common type system performs the following functions:
Establishes a framework that helps enable cross-language integration, type safety, and high performance code execution.
Provides an object-oriented model that supports the complete implementation of many programming languages.
Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.

What’s SingleCall activation mode used for?

If the server object is instantiated for responding to just one single request, the request should be made in SingleCall mode.

What is .Net Framework?

.Net Framework provides a foundation upon which .net application and xml webservices are built and executed.

Does C# support multiple inheritance?

No, use interfaces instead.

What's the difference between login controls and Forms authentication?

Login controls are an easy way to implement Forms authentication without having to write any code. For example, the Login control performs the same functions you would normally perform when using the FormsAuthentication class—prompt for user credentials, validate them, and issue the authentication ticket—but with all the functionality wrapped in a control that you can just drag from the Toolbox in Visual Studio. Under the covers, the login control uses the FormsAuthentication class (for example, to issue the authentication ticket) and ASP.NET membership (to validate the user credentials). Naturally, you can still use Forms authentication yourself, and applications you have that currently use it will continue to run.

What is .Net Platform?

Microsoft .NET is a software development platform based on virtual machine architecture. Dot Net Platform is:
Language Independent – dot net application can be developed different languages (such as C#, VB, C++, etc.)
Platform Independent – dot net application can be run on any operating system which has .net framework installed.
Hardware Independent – dot net application can run on any hardware configuration
It allows us to build windows based application, web based application, web service, mobile application, etc.

What is Postback?

When an action occurs (like button click), the page containing all the controls within the tag performs an HTTP POST, while having itself as the target URL. This is called Postback.

What is CLR (Common Language Runtime)?

CLR provides a environment in which program are executed, it activate object, perform security check on them, lay them out in the memory, execute them and garbage collect them.
The common Language Runtime (CLR) a rich set of features for cross-language development and deployment. CLR supports both Object Oriented Languages as well as procedural languages. CLR provides security, garbage collection, cross language exception handling, cross language inheritance and so on.

What is Component?

It is a set pre-compiled class, which is reusable. For now, just stick to it at the end of article you will practically understand how it is reusable piece of code.

Difference between managed and unmanaged code?

Managed Code :Code that is executed by the CLR is Managed code
Unmanaged Code :Code that is directly executed by the Operating System, not by CLR is known as un-managed code.

Describe the difference between inline and code behind.

Inline code is written along side the HTML in a page. There is no separate distinction between design code and logic code. Code-behind is code written in a separate file and referenced by the .aspx page

What is a Page Life Cycle of an ASP.Net page?

There are various stages described as under.
Init
LoadViewState
LoadPostBackData
Load
RaisePostBackDataChangedEvent
RaisePostBackEvents
Pre-Render
SaveViewState
Render
Unload

What is serialization?

Serialization is the process of converting an object into a stream of bytes. De-serialization is the opposite process of creating an object from a stream of bytes. Serialization/De-serialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database). There are two separate mechanisms provided by the .NET class library for serialization - XmlSerializer and SoapFormatter and BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting.

What is Marshalling?

Marshaling is a process of making an object in one process (the server) available to another process (the client). There are two ways to achieve the marshalling.
i. Marshal by value: the server creates a copy of the object passes the copy to the client. When a client makes a call to an object marshaled by value (MBV), the server creates an exact copy and sends that copy to the client. The client can then use the object's data and executable functionality directly within its own process or application domain without making additional calls to the server. Objects that the application accesses frequently are best remoted using MBV.
ii. Marshal by reference: the client creates a proxy for the object and then uses the proxy to access the object. When a client makes a call to an object marshaled by reference (MBR), the .NET framework creates a proxy in the client's application domain and the client uses that proxy to access the original object on the server. Large objects that the application accesses relatively infrequently are good candidates for MBR.

Difference between Overloading and Overriding ?

Overloading:
Same function name and different parameters is called overloading.

function ss(int a,int b)

function ss(int a,int b,int d)
Overriding:
The base class method is override by the derived class.
class a
{
private int dd()
{
console.writeline("hai")
}
}
class b inherits a
{
private int dd()
{
console writeline("hai guys")
}
}
the output is
hai guys


What are the types of Authentication?

There are 3 types of Authentication.  Windows, Forms and Passport Authentication.
Windows authentication uses the security features integrated into the Windows NT and Windows XP operating systems to authenticate and authorize Web application users.
Forms authentication allows you to create your own list/database of users and validate the identity of those users when they visit your Web site.
Passport authentication uses the Microsoft centralized authentication provider to identify users. Passport provides a way to for users to use a single identity across multiple Web applications. To use Passport authentication in your Web application, you must install the Passport SDK.

What is Authentication and Authorization?

Authentication is the process of identifying users. Authentication is identifying/validating the user against the credentials (username and password) and Authorization performs after authentication. Authorization is the process of granting access to those users based on identity. Authorization allowing access of specific resource to user.

How a base class method is hidden?

Hiding a base class method by declaring a method in derived class with keyword new. This will override the base class method and old method will be suppressed.

What’s the difference between System.String and System.StringBuilder classes?

System.String is immutable, System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

What is the difference between const and static readonly?

If you need to alert a user that his session will time out. This is how to do it. Add the following code snippet to the OnInit method on the base page of your application.
protected override void OnInit(EventArgs e)
   {
       base.OnInit(e);
       string script = "window.setTimeout(\"alert('Your session expired!');\", " + (Session.Timeout - 1) * 60000 + ")";
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionManager", "<script language=\"javascript\">" + script + "</script>");
   }
The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, whereas the value of a const field is set to a compile time constant.
In the static readonly case, the containing class is allowed to modify it only
in the variable declaration (through a variable initializer)
in the static constructor (instance constructors, if it's not static)
static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time.
Instance readonly fields are also allowed.
Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference.
class Program
{
public static readonly Test test = new Test();
static void Main(string[] args)
{
test.Name = "Program";
test = new Test(); // Error: A static readonly field cannot be assigned to
(except in a static constructor or a variable initializer)
}
}

class Test
{
public string Name;
}
On the other hand, if Test were a value type, then assignment to test.Name would be an error.

How To Add Session Timeout Popup in asp.net

If you need to alert a user that his session will time out. This is how to do it. Add the following code snippet to the OnInit method on the base page of your application.
protected override void OnInit(EventArgs e)
   {
       base.OnInit(e);
       string script = "window.setTimeout(\"alert('Your session expired!');\", " + (Session.Timeout - 1) * 60000 + ")";
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionManager", "<script language=\"javascript\">" + script + "</script>");

   }

How To Use RegularExpressionValidator with FileUpload control

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadTest.aspx.cs" Inherits="FileUploadTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
       <div>
           <table cellpadding="0" cellspacing="0" width="100%">
               <tr>
                   <td>
                       Select File</td>
                   <td>
                       <asp:FileUpload ID="fileUpload" runat="Server" /></td>
                   <td>
                       <td align="left">
                           <asp:RegularExpressionValidator runat="server" ID="valUpTest" ControlToValidate="fileUpload"
                               ErrorMessage="Image Files Only (.doc, .txt, .rtf)" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.doc|.txt|.rtf)$" />
                       </td>
                   </td>
               </tr>
               <tr>
                   <td colspan="2" align="Center">
                       <asp:Button ID="btnSubmit" runat="Server" Text="Submit" OnClick="btnSubmit_Click" />
                   </td>
               </tr>
           </table>
       </div>
   </form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class FileUploadTest : System.Web.UI.Page
{
   string sPath = "Image";
   protected void Page_Load(object sender, EventArgs e)
   {

   }
   protected void btnSubmit_Click(object sender, EventArgs e)
   {
       if (fileUpload.HasFile)
       {


           fileUpload.PostedFile.SaveAs(Server.MapPath(sPath) + "/" + Path.GetFileName(fileUpload.PostedFile.FileName));

       }
   }

}

differences between INSERT select and insert into select?

INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date

FROM Sales_Information

Get Records from ANY table in a Database Matching Specified Value

Overview
§  Transact SQL; TSQL; Search entire database for a value
§  This script/stored procedure when created, then executed, will search every table in the database it has been created on, for the search value the user passes it (can handle wildcard
[edit]
Instructions
1.     EDIT the use quotemaster statement to refer to your own database, i.e. use Northwind;
2.     Then, uncomment the use and go statements immediately following the BEGIN SCRIPT line
3.     Then, select and run (can highlight and press F5 in Query Analyzer) all lines from BEGIN SCRIPT to END SCRIPT (end of this page)
4.     To see it in action, once you have done steps 1 - 3 above.
1.     Edit the database name in the USAGE section below, to refer to your own database
2.     Edit the '%FUELSC%' search term param value (below) with the search term you are looking for---you CAN use wildcards
3.     Select the three lines in the USAGE section below, and execute (can press F5 to execute highlighted text in Query Analyzer)
[edit]
Note
A large database could take several minutes to search through
§  USAGE (once stored proc has been created in your db):
§  use quotemaster; --replace with database name you are using, and UNCOMMENT
§  go --UNCOMMENT
§  exec dbo.GetRecordsWithValInAnyFld '%FUELSC%'; --replace paramater value with search term, and UNCOMMENT
§  BEGIN SCRIPT
§  use quotemaster; --EDIT THIS LINE, TO REFER TO THE DATABASE YOU WILL PLACE SCRIPT IN --go --THEN, UNCOMMENT THIS LINE (go), AND RUN all FROM PREVIOUS LINE To END
[edit]
Code
if exists
(select from sysobjects
      where id = object_id(N'dbo.GetRecordsWithValInAnyFld')
      and OBJECTPROPERTY(id, N'IsProcedure') = 1)
      drop proc dbo.GetRecordsWithValInAnyFld;
go

create procedure dbo.GetRecordsWithValInAnyFld
(@ValToFind varchar(500))
AS
-----------------------------------------------------------------------------------------------------
-- Procedure Name-     dbo.GetRecordsWithValInAnyFld()
--
-- Function Gets Columns/Fields that belong to name passed in
-- Wildcard (%) can be used
-- Input Params @ValToFind varchar(500): term (can use wildcards) to match more loosely
-- Output Params Recordset
-- Return Value 1 => If Successful
-- number => In case of error return the error number with text
-- Date 09/28/2005
-- Author Aendenne C. Armour
-- Modification Log:
-- Version___Modified by_________Mod Date___Summary of Modifications

-- 1.0_______Aendenne C. Armour__9/28/05_____None: Initial Version
-- x.0_______Aendenne C. Armour__4/2/08______To fix prior edits, and to account for other data types
-----------------------------------------------------------------------------------------------------
declare @RowCount int, @Error int, @errTxt varchar(255);
select @RowCount = 0, @Error = 0;

declare @objName varchar(150);
set @objName = 'dbo.GetRecordsWithValInAnyFld';

set nocount on;
set transaction isolation level read uncommitted;

create table #dbTbls
(
      TblName varchar(300)
);


insert into #dbTbls
      (TblName)
      select o.[Name] as TblName
      from sysobjects o with(nolock)
      where o.type = 'U'
      order by TblName;

create table #TblFlds
(
      TblName varchar(300),
      FldName varchar(300)--,
      --DataType varchar(100)
);

insert into #TblFlds
      (TblName, FldName)--, DataType)
      select o.name as TblName, '[' + c.name + ']' as FldName    --,o.Type as ObjTypeAbbr, t.Name as DataType
      from syscolumns c with(nolock)
      inner join sysobjects o on c.id = o.id
      inner join systypes t on c.xusertype = t.xusertype
      where o.type = 'U' and t.name in ('varchar''char''nvarchar''nchar')
      order by TblName, FldName;

declare @tbl varchar(300), @fld varchar(300);
declare @where varchar(7000);
declare @sql varchar(8000);

create table #tmpVal
(
      val varchar(300)
);

--select * from #dbTbls
--select * from #TblFlds

while exists(select TblName from #dbTbls)
begin
      set @where = ' where ';
      insert into #tmpVal
            (val)
            select top 1 TblName as val from #dbTbls;
      select @tbl = val from #tmpVal;

      truncate table #tmpVal;

      set @fld = null;
      while exists(select FldName from #TblFlds where TblName = @tbl)
      begin
            insert into #tmpVal
                  (val)
                  select top 1 FldName from #TblFlds where TblName = @tbl;

            select @fld = val from #tmpVal;
            truncate table #tmpVal;

            set @where = @where + @fld + ' like + @ValToFind + or '
            delete from #TblFlds where TblName = @tbl and FldName = @Fld;
      end

      if @fld is not null
      begin
            set @where = left(@where, len(@where) - 3); --remove last OR
            --got where clause, get records:
            set @sql = 'if (select count(*) from ' + @tbl + ' ' + @where + ') > 0';
            set @sql = @sql + ' select + @tbl + as TblName, * from ' + @tbl + ' ' + @where;
            if len(@sql) >= 7999 set @sql = 'select ' + @tbl + ' as TblName, CHECK TABLE MANUALLY; TOO MANY COLUMNS as WARNING';
            exec(@sql);
            --print @sql;
      end
      delete from #dbTbls where TblName = @tbl;

      if (select count(TblName) from #dbTbls) <= 0
            break;
end

--select * from #tmpVal;

drop table #dbTbls;
drop table #TblFlds;
drop table #tmpVal;

select @Error = @@error, @RowCount = @@rowcount;
if @Error <> 0
      begin
            set @errTxt = 'Exception: ' + @objName + ' occured; Main Select Statement';
            raiserror(@errTxt, 1, 2);
      end
--

go

grant exec on dbo.GetRecordsWithValInAnyFld to public;

go