Asp.Net Javascript Window.open From code Behind

To Open New Window From Window.open From Javascript in Asp.Net Code behind use the Following Code

string script = “window.open(‘../FolderName/frmNewFrom.aspx?RepId=RepId&OtherId=” + lblId.Text + “‘,  ”,’width=800, height=500,top=130,left=90,resizable=yes’);”;
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), “PageName”, script, true);

Sql Server Pass Comma Seperated Parameter in Procedure

How to Pass Multi-Value Parameters to SQL Server Stored Procedure

I got This Article From http://www.dotnetspider.com/

To use  Comma Seperated parameter value like 1,2,3  Make Following Function in Sql Server

ALTER FUNCTION [dbo].[fn_Split_Up_Ids]
(
@Param_Ids varchar(500)
)
RETURNS @Id_Table TABLE(IDField int)

AS
BEGIN
IF (LEN(@Param_Ids) <= 0)
RETURN

DECLARE @CommaPos smallint
SET @CommaPos = CHARINDEX(‘,’, RTRIM(LTRIM(@Param_Ids)))

IF @CommaPos = 0
INSERT INTO @Id_Table
VALUES(CONVERT(BIGINT ,RTRIM(LTRIM(@Param_Ids))))
ELSE
BEGIN
WHILE LEN(@Param_Ids) > 1
BEGIN
SET @CommaPos = CHARINDEX(‘,’, RTRIM(LTRIM(@Param_Ids)))
INSERT INTO @Id_Table
VALUES(CONVERT(INT ,SUBSTRING(RTRIM(LTRIM(@Param_Ids)),1, @CommaPos – 1)))
SET @Param_Ids = SUBSTRING(RTRIM(LTRIM(@Param_Ids)), @CommaPos + 1 , LEN(RTRIM(LTRIM(@Param_Ids))))
SET @CommaPos = CHARINDEX(‘,’, RTRIM(LTRIM(@Param_Ids)))
IF @CommaPos = 0
BEGIN
INSERT INTO @Id_Table VALUES(CONVERT(INT ,RTRIM(LTRIM(@Param_Ids))))
BREAK
END
END
END
RETURN
END

And From Above Function

To use the id in the IN clause of the SELECT statement

SELECT * FROM COUNTRY
WHERE Country_Id IN (SELECT * FROM dbo.fn_Split_Up_Ids(‘9,4,2,6,10’))

if you use this values from parameter than

SELECT * FROM COUNTRY
WHERE Country_Id IN (@Country_List)

But this will not work if you write this query in a stored procedure. Therefore you need to use the above function to pass the multi-value paramters to a stored procedure.

The Above Function returns data in integer so for parameter which are in   varchar use below function
This Function will return value in Varchar
Alter FUNCTION [dbo].[fn_Split_Up_Ids]
(
@Param_Ids varchar(500)
)
RETURNS @Id_Table TABLE(IDField varchar(1000))

AS
BEGIN
IF (LEN(@Param_Ids) <= 0)
RETURN

DECLARE @CommaPos smallint
SET @CommaPos = CHARINDEX(‘,’, RTRIM(LTRIM(@Param_Ids)))

IF @CommaPos = 0
INSERT INTO @Id_Table
VALUES (RTRIM(LTRIM(@Param_Ids)))
ELSE
BEGIN
WHILE LEN(@Param_Ids) > 1
BEGIN
SET @CommaPos = CHARINDEX(‘,’, RTRIM(LTRIM(@Param_Ids)))
INSERT INTO @Id_Table
VALUES(SUBSTRING(RTRIM(LTRIM(@Param_Ids)),1, @CommaPos – 1))
SET @Param_Ids = SUBSTRING(RTRIM(LTRIM(@Param_Ids)), @CommaPos + 1 , LEN(RTRIM(LTRIM(@Param_Ids))))
SET @CommaPos = CHARINDEX(‘,’, RTRIM(LTRIM(@Param_Ids)))
IF @CommaPos = 0
BEGIN
–INSERT INTO @Id_Table VALUES(CONVERT(INT ,RTRIM(LTRIM(@Param_Ids))))
INSERT INTO @Id_Table VALUES(RTRIM(LTRIM(@Param_Ids)))
BREAK
END
END
END
RETURN
END

Asp.Net Javascript ShowMessage and Alert Message From CodeBehind

To Display Message of Javacript From Code Behind File Use Following Code

if (lblId.Text == “”)
{
ShowMessage(“Please Select Atleat One Record From Grid”, this.Page);
}
public void ShowMessage(string Msg,System.Web.UI.Page ObjPage)
{
char s1 = ‘”‘;
string s = “alert(” + s1 + Msg + s1 + “);”;
ScriptManager.RegisterClientScriptBlock(ObjPage, this.GetType(), “ShowMessage”, s, true);
}
public void ShowAlert(string message, System.Web.UI.Page pg)
{

StringBuilder sb = new StringBuilder();
message = message.Replace(“\””, “\\\””);
sb.Append(“alert(\””);
sb.Append(“alert(” + message + “)”);
sb.Append(message);
sb.Append(“\”);”);
ScriptManager.RegisterClientScriptBlock(pg, this.GetType(), “showalert”, sb.ToString(), true);
}

Dropdown For Loop to Fetch Day. Month and Year Dropdow

For Loop to Fetch Day. Month and Year

for (int i = 1; i <=31; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
DropDownDay.Items.Add(item.Value);
}
//Inserting month in the month dropdown list.
for (int i = 1; i <=12; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
DropDownMonth.Items.Add(item.Value);
}
//Inserting year in the year dropdown list.
for (int i = 1970; i <=2009; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
DropDownYear.Items.Add(item.Value);
}

Asp.Net Print WebPage From Javascript

To make Print Of Asp.Net Page Use following Javascript.

And Pass Div’s id to ptinrt Particular Portion Of Page.

<script language=”javascript”>
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open(”,”,’letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0′);
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;
}
</script>

Call Above Javascript On button Like

<asp:Button ID=”Button1″ runat=”server” OnClientClick=”javascript:CallPrint(‘Report’);” Text=”Print Preview” />

@@IDENTITY And @@ROWCOUNT

@@IDENTITY :
After an INSERT, SELECT INTO, or bulk copy statement is completed,
@@IDENTITY contains the last identity value that is generated by the statement.
If the statement did not affect any tables with identity columns, @@IDENTITY returns NULL.
If multiple rows are inserted, generating multiple identity values, @@IDENTITY returns
the last identity value generated.

@@ROWCOUNT :
Transact-SQL statements can set the value in @@ROWCOUNT in the following ways:
Set @@ROWCOUNT to the number of rows affected or read. Rows may or may not be sent to the client.
Preserve @@ROWCOUNT from the previous statement execution.
Reset @@ROWCOUNT to 0 but do not return the value to the client.