Set Confirmation Message for Gridview Delete protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //suppose you have a link button column LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); l.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this record?'"); } } Or Note: Write this code in LinkButton OnClientClick Event "return confirm('You sure you want to delete the record?'); Alert for Button Write in Page Load btnClick.Attributes.Add("onClick", "alert('Ouch, you clicked me!');"); Set Confirmation Message for Button protected void Page_Load(object sender, EventArgs e){ //Set the button's client-side onmouseover event btnDelete.Attributes.Add("onClick", "return confirm('You sure you want to delete the record?');"); } Maintaining Page Scrolling Position Note: Write this code in first line of Inline Code [ Ex: <%@ Page MaintainScrollPositionOnPostback="true" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>] <%@ Page ... MaintainScrollPositionOnPostback="true" %> Find Screen width and Screen Height Note: Write this code in <head> . <Script language = JavaScript> UserWidth = window.screen.width UserHeight = window.screen.height UserWidth = "Screen Width = " + UserWidth UserHeight = " Screen Height = " + UserHeight alert(UserWidth + UserHeight) </Script> Move Browser Back or Forward window.history.back() & window.history.forward() <Script language = JavaScript> alert("Sorry, this page is under construction") window.history.back() </Script > <Script language = JavaScript> window.history.go( -2 ) </Script > The minus two means back two pages. To go forward, just remove the minus sign (-). Find Browser Information Note: The navigator object is used to reveal information about the browser your visitors are using. <Script language = JavaScript> alert(navigator.appName) alert(window.navigator.userAgent) </SCRIPT> Window Object The window object is actually at the top of the DOM tree. It's the boss man of the Document Object Model. If we we're being strictly accurate, we should have been using this: Ex: window.document.write("Hello") window.navigator.userAgent window.screen.height JavaScript Rollover Note: Write code in <body> <A HREF =# onmouseout="document.images.but1.src= 'pointer1.jpg'" OnMouseOver = "document.images.but1.src= 'pointer2.jpg'"> <IMG SRC = "pointer1.jpg" NAME = "but1" Border = 0> </A> Set & Alert Page Title <Script Language = JavaScript> alert(document.title) </Script> Javascript Document document.bgColor = 'Orange' document.fgColor = 'Yellow' Form Validation Note: For Check Empty Textbox Value in ContentPlaceHolder (Using Master Page) <Script Language = JavaScript> function validateme() { if(document.getElementById("<%=txtOrddat.ClientID %>").value=="") { alert("!Please enter Order Date"); document.getElementById("<%=txtOrddat.ClientID %>").focus(); return false; } } </Script> cont… Form Name: f1 Name textbox: Name Email textbox: Email Comments text area: Comments Likes Checkboxes: Liked Dislikes Checkboxes: Hated function Validate() { Message = "" Message = Message + CheckName() Message = Message + CheckEmail() Message = Message + CheckComments() Message = Message + CheckLikes() Message = Message + CheckHates() if (Message == "") { return true } else { alert(Message) return false } } Validate Name function CheckName() { UserName = document.f1.Name.value if (UserName == "") { Message = "Something's wrong with your name" + "\n" } else { Message = "" } return Message } Validate E-Mail function CheckEmail() { email = document.f1.Email.value AtPos = email.indexOf("@") StopPos = email.lastIndexOf(".") Message = "" if (email == "") { Message = "Not a valid Email address" + "\n" } cont… if (AtPos == -1 || StopPos == -1) { Message = "Not a valid email address" } if (StopPos < AtPos) { Message = "Not a valid email address" } if (StopPos - AtPos == 1) { Message = "Not a valid email address" } return Message } Validate a Drop Down Box Note: Write code in <form> <SELECT NAME = s1 onchange=GetSelectedItem1()> <OPTION VALUE = "NE" selected >North East</OPTION> <OPTION VALUE = "NW"> North West</OPTION> <OPTION VALUE = "SE">South East</OPTION> <OPTION VALUE = "SW">South West</OPTION> <OPTION VALUE = "Midlands">Midlands</OPTION> </SELECT> <Script Language = JavaScript> function GetSelectedItem1() { len = document.f1.s1.length i = 0 chosen = "none" for (i = 0; i < len; i++) { if (document.f1.s1[i].selected) { chosen = document.f1.s1[i].value } } alert(chosen) } </Script> Validate a List Box <SELECT NAME = s2 size = 5 multiple onchange=GetSelectedItem()> <OPTION VALUE = "Shopping" selected >Shopping</OPTION> <OPTION VALUE = "Fashion">Fashion</OPTION> <OPTION VALUE = "Opera">Opera</OPTION> <OPTION VALUE = "Books">Books</OPTION> <OPTION VALUE = "Pop Music">Pop Music</OPTION> </SELECT> <Script Language = JavaScript> function GetSelectedItem() { len = doc
Set Confirmation Message for Gridview Delete
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
//suppose you have a link button column
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick",
"javascript:return confirm('Are you sure you want to delete this record?'");
}
Or
Note: Write this code in LinkButton OnClientClick Event
"return confirm('You sure you want to delete the record?');
Alert for Button
Write in Page Load
btnClick.Attributes.Add("onClick", "alert('Ouch, you clicked me!');");
Set Confirmation Message for Button
protected void Page_Load(object sender, EventArgs e){
//Set the button's client-side onmouseover event
btnDelete.Attributes.Add("onClick",
"return confirm('You sure you want to delete the record?');");
Maintaining Page Scrolling Position
Note: Write this code in first line of Inline Code [ Ex: <%@ Page MaintainScrollPositionOnPostback="true" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>]
<%@ Page ... MaintainScrollPositionOnPostback="true" %>
Find Screen width and Screen Height
Note: Write this code in <head> .
<Script language = JavaScript>
UserWidth = window.screen.width
UserHeight = window.screen.height
UserWidth = "Screen Width = " + UserWidth
UserHeight = " Screen Height = " + UserHeight
alert(UserWidth + UserHeight)
</Script>
Move Browser Back or Forward
window.history.back() & window.history.forward()
alert("Sorry, this page is under construction")
window.history.back()
</Script >
window.history.go( -2 )
The minus two means back two pages. To go forward, just remove the minus sign (-).
Find Browser Information
Note: The navigator object is used to reveal information about the browser your visitors are using.
alert(navigator.appName)
alert(window.navigator.userAgent)
</SCRIPT>
Window Object
The window object is actually at the top of the DOM tree. It's the boss man of the Document Object Model. If we we're being strictly accurate, we should have been using this:
Ex:
window.document.write("Hello")
window.navigator.userAgent
window.screen.height
JavaScript Rollover
Note: Write code in <body>
<A HREF =# onmouseout="document.images.but1.src= 'pointer1.jpg'" OnMouseOver = "document.images.but1.src= 'pointer2.jpg'">
<IMG SRC = "pointer1.jpg" NAME = "but1" Border = 0>
</A>
Set & Alert Page Title
<Script Language = JavaScript>
alert(document.title)
Javascript Document
document.bgColor = 'Orange'
document.fgColor = 'Yellow'
Form Validation
Note: For Check Empty Textbox Value in ContentPlaceHolder (Using Master Page)
function validateme()
if(document.getElementById("<%=txtOrddat.ClientID %>").value=="")
alert("!Please enter Order Date");
document.getElementById("<%=txtOrddat.ClientID %>").focus();
return false;
cont…
Form Name: f1 Name textbox: Name Email textbox: Email Comments text area: Comments Likes Checkboxes: Liked Dislikes Checkboxes: Hated
function Validate() {
Message = ""
Message = Message + CheckName()
Message = Message + CheckEmail()
Message = Message + CheckComments()
Message = Message + CheckLikes()
Message = Message + CheckHates()
if (Message == "") {
return true
else {
alert(Message)
return false
Validate Name
function CheckName() {
UserName = document.f1.Name.value
if (UserName == "") {
Message = "Something's wrong with your name" + "\n"
return Message
Validate E-Mail
function CheckEmail() {
email = document.f1.Email.value
AtPos = email.indexOf("@")
StopPos = email.lastIndexOf(".")
if (email == "") {
Message = "Not a valid Email address" + "\n"
if (AtPos == -1 || StopPos == -1) {
Message = "Not a valid email address"
if (StopPos < AtPos) {
if (StopPos - AtPos == 1) {
Validate a Drop Down Box
Note: Write code in <form>
<SELECT NAME = s1 onchange=GetSelectedItem1()>
<OPTION VALUE = "NE" selected >North East</OPTION>
<OPTION VALUE = "NW"> North West</OPTION>
<OPTION VALUE = "SE">South East</OPTION>
<OPTION VALUE = "SW">South West</OPTION>
<OPTION VALUE = "Midlands">Midlands</OPTION>
</SELECT>
function GetSelectedItem1() {
len = document.f1.s1.length
i = 0
chosen = "none"
for (i = 0; i < len; i++) {
if (document.f1.s1[i].selected) {
chosen = document.f1.s1[i].value
alert(chosen)
Validate a List Box
<SELECT NAME = s2 size = 5 multiple onchange=GetSelectedItem()>
<OPTION VALUE = "Shopping" selected >Shopping</OPTION>
<OPTION VALUE = "Fashion">Fashion</OPTION>
<OPTION VALUE = "Opera">Opera</OPTION>
<OPTION VALUE = "Books">Books</OPTION>
<OPTION VALUE = "Pop Music">Pop Music</OPTION>
function GetSelectedItem() {
len = doc