Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - How we can attach javascript code to a button using code behind in asp.net using C#.
Blog
 
# Sunday, June 21, 2009

we can attach javascript in code behind using this style

 

private void Page_Load(object sender, System.EventArgs e)

{

System.Text.StringBuilder StrValidation = new System.Text.StringBuilder();

//Appending javascript in this string builder

StrValidation.AppendFormat("{0}",@"<script language='javascript'>

function validateForm()

{

if (isBlank(document.baseForm.txtEmail.value)) {

alert('Email ID can not be blank1 !');

document.baseForm.txtEmail.focus();

return false;

}

if (isBlank(document.baseForm.txtSubject.value)) {

alert('Subject can not be blank !');

document.baseForm.txtSubject.focus();

return false;

}

if (isBlank(document.baseForm.txtMessage.value)) {

alert('Please Enter Message in Message Box !');

document.baseForm.txtMessage.focus();

return false;

}

return true;

} </script>");

Page.RegisterClientScriptBlock("AddValidation",StrValidation.ToString());

this.ibtnSubmit.Attributes.Add("onClick", "return validateForm();");

Sunday, June 21, 2009 11:21:26 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   asp.net  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: