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();");