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