-
September 9th, 2010, 09:12 AM
#1
Contact form for SharePoint
I just found a code to build a contact form:
http://www.java2s.com/Code/ASP/Valid...iladdressC.htm
This part works fine for me, but now I did add an RequiredFieldValidator.#
Here's the code e.g. txtEmailAddress:
RequiredFieldValidator FieldEmailValidieren = new RequiredFieldValidator();
FieldEmailValidieren.ID = "_FieldEmailValidieren";
FieldEmailValidieren.ControlToValidate = txtEmailAddress.ID;
FieldEmailValidieren.Text = "<br>The E-Mail you have entered is not valid!";
FieldEmailValidieren.ErrorMessage = "Field 'Email' is empty";
FieldEmailValidieren.Display = ValidatorDisplay.Static;
Controls.Add(FieldEmailValidieren);
This works fine for me, too, but the problem is that I need an RegularExpressionValidator.
Can somebody help me herewith?
fnatichohn
-
September 9th, 2010, 12:37 PM
#2
Re: Contact form for SharePoint
Code:
<td colspan="3" style="text-align: left">
<asp:TextBox ID="txtEmailAddress" runat="server" Width="241px" MaxLength="100"></asp:TextBox>
<asp:requiredfieldvalidator id="RequiredFieldValidator3"
controltovalidate="txtEmailAddress"
errormessage="Email Address."
text=" *" runat="server"
SetFocusOnError="True" />
<asp:CustomValidator id="CustomValidator1"
controltovalidate="txtEmailAddress"
OnServerValidate="ValidateEmailFormat"
errormessage="The email address format is not valid. Format: someone@company.com"
text=" *" runat="server" SetFocusOnError="True" />
</td>
Then with a custom validator, in the codebehind,
Code:
// Function: ValidateEmailFormat
// Description: Matches the Email expression, to ensure it is a valid format.
protected void ValidateEmailFormat(object source, ServerValidateEventArgs args)
{
// match the format
if (System.Text.RegularExpressions.Regex.IsMatch(txtEmailAddress.Text.ToString(), @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
args.IsValid = true;
else
args.IsValid = false;
}
-Quinn
I hope it helps! If it does please rate up.
-
September 13th, 2010, 06:07 AM
#3
Re: Contact form for SharePoint
Hi Quinn!
First all thanks for your help, but I don't understand everything.
Do I have to replace anything from my code to use yours or do you I only have to add the last part?
If I do so I get the following errors: http://pastie.org/1155514
Sorry, but I'm absolutely a freshman to C-Sharp.
I hope you understand and can help me with my problem.
-
September 24th, 2010, 05:58 PM
#4
Re: Contact form for SharePoint
Originally Posted by QuinnJohns
Code:
<td colspan="3" style="text-align: left">
<asp:TextBox ID="txtEmailAddress" runat="server" Width="241px" MaxLength="100"></asp:TextBox>
<asp:requiredfieldvalidator id="RequiredFieldValidator3"
controltovalidate="txtEmailAddress"
errormessage="Email Address."
text=" *" runat="server"
SetFocusOnError="True" />
<asp:CustomValidator id="CustomValidator1"
controltovalidate="txtEmailAddress"
OnServerValidate="ValidateEmailFormat"
errormessage="The email address format is not valid. Format: someone@company.com"
text=" *" runat="server" SetFocusOnError="True" />
</td>
Then with a custom validator, in the codebehind,
Code:
// Function: ValidateEmailFormat
// Description: Matches the Email expression, to ensure it is a valid format.
protected void ValidateEmailFormat(object source, ServerValidateEventArgs args)
{
// match the format
if (System.Text.RegularExpressions.Regex.IsMatch(txtEmailAddress.Text.ToString(), @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
args.IsValid = true;
else
args.IsValid = false;
}
-Quinn
I hope it helps! If it does please rate up.
So, the top portion goes into the .ASPX page.
The bottom part, goes into the corresponding .aspx.cs page.
-
September 27th, 2010, 07:06 AM
#5
Re: Contact form for SharePoint
Well, I'm okay with the bottom part, but the top portion is harder for me.
Do I have to create a .ASPX page?
This is a screenshot of my solution explorer: http://picfront.org/d/7R91
edit: I'm sorry. I did post the wrong link in my very first post. Here's the right one: http://www.codeproject.com/KB/sharep...ntactForm.aspx
Last edited by fnatichohn; September 28th, 2010 at 06:27 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|