Validation Controls RadTextBox

2 posts, 0 answers
  1. Ben Paul
    Ben Paul avatar
    1 posts
    Member since:
    Dec 2009

    Posted 24 Dec 2009 Link to this post

    I'm more of a Designer/Front-End guy but trying hard to understand .NET and learn as much as I can. I had a developer help me with some of this, but I'm still stumped.

    I'm confused as to how I can get my form to validate using the validation controls.

    Whenever I call the onClick="send_Click" it bypasses the validation and runs the form string and redirects to my thankyou.aspx.

    When I replace it with the onClientClick it validates but fails to run the code in the aspx.cs file.

    Here is a snippet of what is on the form page aka howtoget.aspx.

    <div class="formboxit2">
            <div class="contactlabelist2"><span style="color:#246FF5">*</span><label>Email</label></div>
            <div class="contactinputist">
                <telerik:RadTextBox ID="Email" runat="server" Height="19px" Width="200px" BorderColor="White" BorderStyle="Solid" BorderWidth="2px" CssClass="radPad" Skin="Office2007" Font-Bold="True" Font-Names="Arial" Font-Size="12px" LabelCssClass="">
                    <FocusedStyle BorderColor="#246FF5" BorderStyle="Solid" BorderWidth="2px" />
                    <HoveredStyle BorderColor="#246FF5" BorderStyle="Solid" BorderWidth="2px" />
                </telerik:RadTextBox>
                
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="Dynamic"
                ControlToValidate="Email" ErrorMessage="The textbox can not be empty!" EnableClientScript="False" />
            </div>
    </div>
    <div class="formboxitM">
        <div class="contactlabelist"><label>Message</label></div>
        <div class="contactinputist">
            <telerik:RadTextBox ID="Message" runat="server" Height="114px" TextMode="MultiLine" Width="634px" BorderColor="White" BorderStyle="Solid" BorderWidth="2px" Skin="Office2007" Font-Bold="True" Font-Names="Arial" Font-Size="12px" LabelCssClass="">
                <FocusedStyle BorderColor="#246FF5" BorderStyle="Solid" BorderWidth="2px" />
                <HoveredStyle BorderColor="#246FF5" BorderStyle="Solid" BorderWidth="2px" />
            </telerik:RadTextBox>
        </div>
    </div>
    <div class="contactinputistSub"><asp:button runat="server" ID="send" onClick="send_Click" BorderStyle="None" BorderWidth="0px" CssClass="swerps" /></div>
    <div class="inquiry">*Your information will only be used for this inquiry.</div>   


    and here is what I have on the aspx.cs

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net.Mail;
    using Telerik.Web.UI;

    namespace domain.com
    {
        public partial class howtoget : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
           }

            protected void send_Click(object sender, EventArgs e)
            {
                try
                {
                    string firstname = this.FirstName.Text;
                    string lastname = this.LastName.Text;
                    string phone = this.Phone.Text;
                    string email = this.Email.Text;
                    string messageoftext = this.Message.Text;
                    string bodyoftext = firstname + " " + lastname + " " + "has requested to be contacted. " + firstname +
                        "'s email address is: " + email + " . You may contact this person at: " + phone + " . " + firstname+ " has left message: " + messageoftext;
                    MailMessage message = new MailMessage("info@domain.com", "info@domain.com", "Customer Request", bodyoftext);
                    SmtpClient emailClient = new SmtpClient("relay-hosting.secureserver.net ");
                    message.IsBodyHtml = true;
                    emailClient.Send(message);
                    Response.Redirect("thankyou.aspx");
                }
                catch (Exception mailex)
                {
                    Response.Write(mailex.ToString());
                }
     
            }
        }
    }


  2. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 26 Dec 2009 Link to this post

    1) Well EnableClientScript is false, so you're going to be going back to the server to validate.  You should remove that (unless you want to postback...) http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.enableclientscript%28VS.80%29.aspx

    2) Try setting a ValidationGroup  on the TextBoxes, the RequiredFieldValidators, and the submit button....it'll link them all together.

    3) If you need to validate on the serverside, use a CustomValidator link .  It'll allow you to stop your click events from running if your page isnt in a Valid State.  Useful for scenarios where a user has typed in some text which passes the "RequiredValidator", but needs some extra validation.

    Give those a go :)
    Steve
Back to Top