|
|
I see you have created a new login to ask the same question again. And you still posted a link to the code rather than posting the code in your message.
Don't create redundant logins unnecessarily.
Don't repost the same question.
Don't post links to code. Post the code here in your message. Format it well. Make a minimal example instead of posting your full code.
|
|
|
|
|
I have made a contact me form for my website. When I was testing it with f5 in ASP.Net, the contact me page just reloaded itself after I submitted the information (like the Name, Phone Number, Email etc). But I still received the email containing the information I inputted into the Text Boxes in the Form.
So I decided to include a Try-Catch and redirect to a failure or success page depending on if it sent successfully... it always redirected to failure.html but I still received the email which is weird.
So I decided to FTP the site, it still redirects to failure.html but I don't receive any email anymore. There is clearly a problem here. I get no errors and no exception etc, so I have no indication onto where I'm going wrong. I will include all my coding.
contactme.aspx (just the form):
<div runat="server" id="form01">
<table width="325" border="0">
<tr>
<td height="30" class="left"><asp:label runat="server" for="name">Name:</asp:label></td>
<td>
<asp:TextBox runat="server" class="input" type="text" name="name" id="name"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="name" ErrorMessage="Please input your name.">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td height="30" class="left"><asp:label runat="server" for="number">Number:</asp:label></td>
<td><asp:TextBox runat="server" class="input" type="text" name="number" id="number"></asp:TextBox></td>
<td> </td>
</tr>
<tr>
<td height="30" class="left"><asp:label runat="server" for="email">Email:</asp:label></td>
<td><asp:TextBox runat="server" class="input" type="text" name="email" id="email"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="email" ErrorMessage="Please input an email address.">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="email" ErrorMessage="Please enter a valid email address."
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="left"><asp:label runat="server" for="message">Message:</asp:label></td>
<td>
<asp:TextBox runat="server" class="input" name="essage" id="message" cols="45"
rows="3" TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="message" ErrorMessage="Please input a message.">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="left"> </td>
<td class="right"><label>
<asp:button runat="server" class="submitBtn" name="submit"
Text="Submit" id="cmdSubmit" onclick="submit_Click" /> <asp:ValidationSummary
ID="ValidationSummary" runat="server" CssClass="rightSpec"
DisplayMode="List" />
</label>
</td>
</tr>
</table>
</div>
contactme.aspx.cs:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
public partial class contactme : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submit_Click(object sender, EventArgs e)
{
MailMessage messageC = new MailMessage();
MailAddress to = new MailAddress("webdesign@malachijones.co.uk");
messageC.To.Add(to);
messageC.From = new MailAddress("webdesign@malachijones.co.uk", "site request");
messageC.Subject = "malachijones.co.uk website request";
messageC.IsBodyHtml = true;
messageC.Body = "<html><head></head><body>" +
"<p></p>" +
"<p><strong>Name:</strong> " + name.Text + "</p>" +
"<p><strong>Phone Number:</strong> " + number.Text + "</p>" +
"<p><strong>Email Address:</strong> " + email.Text + "</p>" +
"<p><strong>Message:</strong> " + message.Text + "</p>" +
"</body></html>";
SmtpClient smtpClient = new SmtpClient("smtpout.europe.secureserver.net");
smtpClient.Credentials = new System.Net.NetworkCredential("webdesign@malachijones.co.uk", "My Password");
smtpClient.Send(messageC);
}
}
web.config:
<system.net>
<mailSettings>
<smtp from="webdesign@malachijones.co.uk">
<network host="smtpout.europe.secureserver.net" port="25" userName="webdesign@malachijones.co.uk" password="My Password"/>
</smtp>
</mailSettings>
</system.net>
Thanks in advance for any help.
Respect,
(*$malli$*)modified on Thursday, February 18, 2010 7:35 PM
|
|
|
|
|
No one is going to read this unformatted garbage
Read
this[^] and pay attention to item #7 I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Sorry about that, I have reformatted it.
Respect,
(*$malli$*)
|
|
|
|
|
I have no idea about asp.net, but the first thing I would do is actually try to catch the exception!
try
{
Response.Redirect("success.html");
}
catch(Exception ex)
{
Response.Redirect("failure.html");
}
|
|
|
|
|
Ok thanks for the reply, I'll trying that now.
*EDIT* I posted the exception but it got deleted I think. I changed the catch to:
Response.Redirect("success.html");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
I had to FTP the site before the exception would show. It kept going to success.html when I tested with Localhost. I didn't receive any email after I FTP'ed either.
Respect,
(*$malli$*)modified on Thursday, February 18, 2010 10:08 PM
|
|
|
|
|
Ok I changed the Catch to this:
Response.Redirect("success.html");
}
catch(Exception ex)
{
Label1.Text = "ex message: " + ex.Message;
}
After I changed it, it redirected to "success.html" and I still got the email, so I decided to FTP it to see if it really was "successful".... It wasnt, and my ex message was: Failure sending mail.
No email and no details at all :/.
Thanks again for the reply.
Respct,
(*$malli$*)
|
|
|
|
|
Have a look at the ex.Innerexception , it may contain a clue as to why it failed if it has a value.
|
|
|
|
|
Where do I place ex.Innerexception please?
Respect,
(*$malli$*)
|
|
|
|
|
put a breakpoint in your catch block and when it's hit, hover your mouse over the ex
You will now be able to examine all the exception's properties including the InnerException[^] property.
|
|
|
|
|
Ok thanks for the help, I got to view it at last...
Now the fact that I get the email when testing through Localhost but not when I FTP the website, does that mean that something is wrong with my SMTP details? here is the top half of the InnerException:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 188.121.53.3:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress
would that IP address maybe be blocked by GoDaddy or something?
Respect,
(*$malli$*)
|
|
|
|
|
hello
I want to know how I could solve this problem. child forms goes behind panel in the parent form .and I just could change background color I want to place a picture on the background how could I do this?
|
|
|
|
|
MDI - set background picture here[^].Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
thank you a lot. but how about panel ? when I add a panel to the parent form,child form goes behind panel.
|
|
|
|
|
There is a property called BringToFront() .
Try using this property on your child control.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
I tested it but it didn't work.
|
|
|
|
|
I ran into this issue myself, you have to dock your panel to get the behavior you want.
|
|
|
|
|
how? I already start to learn c# and I don't know what you mean.
|
|
|
|
|
My apologies for the relatively newbie-ish question -- I'm rather new to C# and WPF programming. Here's an object I'm trying to use with strong influence from Pro WPF in C# 2008 (.NET version 3.5) that's supposed to validate a text box's contents:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace LeanQualityTool
{
public class ValidatedTextBox : TextBox, INotifyPropertyChanged, IDataErrorInfo
{
private string _TextContents = "";
public string TextContents
{
get { return _TextContents; }
set { _TextContents = value;
NotifyPropertyChanged("TextContents");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#region IDataErrorInfo Members
public string Error
{
get { return null; }
}
public string this[string fieldName]
{
get
{
string result = null;
#region For Validating Text
if (fieldName.Contains("Title"))
{
if (this._TextContents.Length == 0)
{
result = "Text should not be blank";
throw new ArgumentException(result);
}
else
{
}
}
#endregion
return result;
}
#endregion
}
}
}
And here's the relevant XAML:
xmlns:vip="clr-namespace:LeanQualityTool"
<vip:ValidatedTextBox Height="23" x:Name="txtJobTitle" HorizontalAlignment="Left" Width="276"
Style="{StaticResource validatedTextBox}">
<TextBox.Text>
<Binding Path="SelectedItem.Title" UpdateSourceTrigger="PropertyChanged"
ValidatesOnDataErrors="True">
</Binding>
</TextBox.Text>
</vip:ValidatedTextBox>
I try to put a breakpoint on the IF statement in the class, but when I debug the app, changing the text in the textbox doesn't even cause the breakpoint to engage. Why isn't the new ValidatedTextBox working?
|
|
|
|
|
Try posting this in the WPF forum. You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
|
Did you really get this code from book? I really need to write a book.
BTW, you are binding to the Text property of the TextField. In code and not automagic binding, what kind of happens is this:
public class TextBox{
public string this[string fieldName]{
get;
set;
}
}
TextBox foo = new TextBox();
foo.Text = "Some Value";
So the Text Property is getting fired. Your codes seems to be:
public class TextBox{
public string Text{
get{...}
set{...}
}
}
TextBox foo = new TextBox();
foo["test"] = "test";
What I think the Author meant was, register the Notify Property event changed from the parent Text Box then call your validate method which should be a method and not an indexor like:
public class TextBox : System.Windows.Forms.TextBox {
protected override void OnTextChanged(EventArgs e) {
base.OnTextChanged(e);
Validate();
}
public void Validate() {
}
}
Of course I am just guessing.
|
|
|
|
|
Worked like a charm!
Let me know if and when you get that book written, okay? I'll buy three copies.
|
|
|
|
|
I have an application which a tabcontrol on it. Each tab has various input boxes of various types (textboxes, gridviews, checkboxes and comboboxes). When the user clicks a tab the applicable data is loaded from a database and the controls on that tab are populated. When the user clicks a different tab, a messagebox should pop up asking if he wants to save his input. That part is not a problem. However, I would only like the box to pop up if he changed any input, or at least clicked inside a control. Is there a global way to sense this? I thought about creating a boolean flag, that gets set in each control change event - however this would seem bulky.
Thanks
Marc
|
|
|
|