CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2010
    Location
    Harrislee
    Posts
    3

    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

  2. #2
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    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.

  3. #3
    Join Date
    Sep 2010
    Location
    Harrislee
    Posts
    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.

  4. #4
    Join Date
    Jul 2005
    Location
    Louisville, KY
    Posts
    201

    Re: Contact form for SharePoint

    Quote Originally Posted by QuinnJohns View Post
    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.

  5. #5
    Join Date
    Sep 2010
    Location
    Harrislee
    Posts
    3

    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
  •  





Click Here to Expand Forum to Full Width

Featured