Get page name from url in javascript

In this tutorial you will learn how to get page name from url in javascript. I have already written a post that teaches same thing and in asp.net. I will recommend you to get page name from url by using client side language such as javascript. Try to write as less server side code as possible because if same thing can be achieved through client side language javascript then there is no need to write server side code and put burden on server. Now let's have a look over how to do so

Get page name from url in javascript.

<script language="javascript">
        var url = window.location.pathname;

        var myPageName = url.substring(url.lastIndexOf('/') + 1);    

        alert(myPageName);
</script>



So this is the way to get page name from url in javascript.


Happy Coding, Keep Coding.



Read more...

create div element dynamically by using javascript

In this tutorial you will learn how to create div element dynamically by using javascript. We will do this by utilizing the DOM features of javascript. Let's have a look over example given below


Create div element dynamically by using javascript

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Create div element dynamically using javascript</title>

<style type="text/css">

.myDivClass
{
color: #999;

padding: 10px;

width: 250px;

height: 150px;

border: solid 1px #666;

}

</style>

<script type="text/javascript" language="javascript">

function CreateDivElement() {

var divElement = document.createElement("div");

divElement.id = "myDiv";

divElement.className = "myDivClass";

divElement.innerHTML = "Hello World!";
document.body.appendChild(divElement);

}

</script>

</head>

<body>

<div>

<input id="myBtn" type="button" value="Click Me" onclick="CreateDivElement();" />

</div>

</body>

</html>
And if you want to want to create div element inside any other html element of page body then nothing to worry. Let's suppose we have a div in our page which id is testDiv like given below
<div id="testDiv">
</div>
and you want to create div inside this testDiv. Just you have to change the last line of CreateDivElement() function from


document.body.appendChild(divElement);
to
document.getElementById('testDiv').appendChild(divElement);


and that's it. I hope you will like this tutorial.


Happy Coding, Keep Coding
Read more...

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...