Learn how to pass the variable value from asp.net code behind to javascript

In this asp.net tutorial you will learn how to pass the variable value from asp.net code behind to javascript. It is quite easy and handy. You must know how to do so because in certain cases you may have to pass value from asp.net code behind to javascript. Let's have a look over how to do so

How to pass the variable value from asp.net code behind to javascript

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to pass the variable value from asp.net code behind to javascript</title>
<script type="text/javascript">
//Getting variable from asp.net code behind
var myMessage = "<%=myMessageFromCodeBehind %>";
alert(myMessage);

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Let's have a look over .cs side
//Declaring protected type string variable 
protected string myMessageFromCodeBehind;

protected void Page_Load(object sender, EventArgs e)
{
//Assigning Value to variable
myMessageFromCodeBehind = "Happy coding, keep coding";
}
I have declared a protected type string variable myMessageFromCodeBehind in asp.net code behind, assign a value to that variable and get it on my .aspx page using javascript given below
var myMessage = "<%=myMessageFromCodeBehind %>";
alert(myMessage);
So this is the proper way to pass the variable value from asp.net code behind to javascript.

Read more...

How to get all store procedures saved in ms sql server database

In this tutorial you will learn how to get all store procedures saved in ms sql server database. Its quite easy and simple. Just you have to do is to write and execute the following query.

How to get all store procedures saved in ms sql server database


SELECT * FROM SYS.OBJECTS WHERE TYPE ='P'
 
This above mentioned query will return you all store procedures placed in your ms sql server database. Sys.Objects is a built-in table in ms sql server that contains information about each and every element of the database.

I love your feedback.
Read more...

learn how to get random records in sql server

In this ms sql server tutorial you will learn how to get random records in sql server. Sometimes you may need to get random records from table in ms sql server database. To do this in ms sql server is quite easy. Let's have a look over example below in which i am getting five random records from visitors table located in ms sql server database.

Get random records in ms sql server

SELECT TOP 5 firstname, lastname, country FROM visitors
ORDER BY NEWID()



The NEWID() system function makes a unique value of the type uniqueidentifier. There is no need to add a new column in your table to get the random records. you just have to include the NEWID() system function in the ORDER BY clause of your SELECT statement. I hope you will like this tutorial.
Read more...