I am a newbie in sharepoint and only for 1 month. I am using sharepoint 2007,.aspx. and doing for an email form with some validation, after user pass the validation the email send.
But I'm getting the error thisWeb is undefined, I create this inside javascript function. I have SPUtility.js and I try to add line like SPWeb thisWeb = site.OpenWeb(SPContext.Current.Web.ID; and this causes my whole function not working. Do I need some .js for SPWeb? Please give me some instruction.
Here is my code:
<script type="text/javascript">
function notEmpty(){
var txt="";
var myTo= document.getElementById('txtTo2');
var myName= document.getElementById('txtName2');
var myFrom= document.getElementById('txtFrom2');
var myBody= document.getElementById('txtBody2');
var sendButton = document.getElementById('sendEmail');
var validateButton = document.getElementById('button1');
var body = ("This email is send from : "+ myName + ", Note here : " +myBody);
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(myTo.value==""||myName.value==""||myFrom.value==""||myBody.value=="")
{
alert("Please Fill In All Fields!");
return false;
}
else if(!(myTo.value.match(mailformat))||!(myFrom.value.match(mailformat)))
{
alert("Invalid Email Address!");
return false;
}
else if(myBody.value.length >5 )
{
alert("Please check body field! 5 characters only");
return false;
}
else
{
try
{
SPUtility.SendEmail(thisWeb, true, false, myTo, myFrom, body);
alert(EmailSend!");
}
catch(err)
{
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
return true;
}
</script>
protected void Btn_SendMail_Click(object sender, EventArgs e) { Microsoft.SharePoint.Utilities.SPUtility.SendEmail(SPContext.Current.Web, true, false, toField, subject, body); ClientScript.RegisterClientScriptBlock (this.GetType(), "confirm", "alert('Thank you. Your message has been successfully sent!')", true); }and It working. Now other problems. It is an asp button. and everytimes I click ok for the validation, the page reload. How to make it not reload? thanks – clipper Jul 29 '12 at 07:20