Wednesday, 12 March 2014

how to disable html5 validation control in asp.net

You may want to leave "type" undeclared in your code "front". You can set this in the code behind (maybe in the Page_Init or Page_Load):
this.Contract.Attributes.Add("type", "tel");

ASP.NET: Send mail html format - Email settings for godday hosting

  1. It is always better to check email settings with godaddy technical support.
  2. You have to use the following relay server as the mail server: relay-hosting.secureserver.net
  3. You do not need to provide any user name & password for this relay server but you need an valid from email address. You have to use default credentials:smtp.UseDefaultCredentials = true; 
  4. You have to turn off ssl connection as it does not support secure connection: smtp.EnableSsl = false;
asp.net web.config file settings:
<appSettings>
    <!--email hosting for godaddy website-->
    <add key="MailServer" value="relay-hosting.secureserver.net"/>
    <add key="Port" value="25"/>
    <!--godaddy hosting does not need username & password-->
    <!--<add key="UserName" value="info@ete-consulting.co.uk"/>
    <add key="Password" value="ete214"/>-->
    <add key="FromMail" value="masuds_mail@yahoo.com"/>
    <add key="SendToMail" value="info@ete-consulting.co.uk" />
  </appSettings>
 
  <system.web>
    <!--custome error mode need to be off or remote only-->
    <customErrors mode="Off"/>
    <!--asp.net c# web application shows error:
    The application attempted to perform an operation not allowed by the security policy. 
    To grant this application the required permission please contact your system administrator or
    change the application's trust level in the configuration file. -->
    <trust level="Full" originUrl=""/>
   

config.cs class file:
public static string SendMail(string subject, string body)
    {
        //function: send html email using asp.net c#
        SmtpClient smtp = new SmtpClient();
        smtp.Host = Config.MailServer;
        smtp.Port = Config.Port;
        //credentials need to set to true for godaddy hosting
        smtp.UseDefaultCredentials = true;
        //godaddy does not support Secure connection
        smtp.EnableSsl = false;
        //smtp.Credentials = new System.Net.NetworkCredential(Config.UserName, Config.Password);
        MailMessage mailMsg = new MailMessage();
        mailMsg.To.Add(Config.SendToMail);
        mailMsg.From = new MailAddress(Config.FromMail);
        mailMsg.Subject = subject;
        mailMsg.Body = body;
        //send html email message.
        //you will be able to use html tag in the message to
        mailMsg.IsBodyHtml = true;
        string msg = null;
        try
        {
            smtp.Send(mailMsg);
        }
        catch (Exception ex)
        {
            msg = ex.Message;
            //throw ex;
        }

        return msg;
    }

aspx.cs coding to send email html formatted
protected void btnStartProject_Click(object sender, EventArgs e)
    {
        //in order to be able to see the html elements in aspx.cs use the runat="server" attribute
        string message, subject, body, name, gender;
        subject = slProjectType.Value;
        name = firstName.Value + " " + lastName.Value;
        if (male.Checked == true)
            gender = "Male";
        else
            gender = "Female";
       
       
        body = "<p>Dear sir,</p>"
            + "<p>I am interested to start a "
            + slProjectType.Value
            + " with your company http://www.ete-consulting.co.uk </P>"

            + "<p><h3>My personal details:</h3>"
            + "</p><p>First name: "
            + firstName.Value
            + "</p><p> Last name: "
            + lastName.Value
            + "</p><p>Gender: "
            + gender
            + "</p><p>My country: "
            + slCountrySelector.Value

            + "</p><p><h3>My contact details</h3>"
            + "</p><p>mobile: "
            + telephone.Value
            + "</p><p>email: "
            + email.Value

            + "</p><p><h3>Project details</h3>"
            + "</p><p>Project type: "
            + slProjectType.Value
            +"</p><p>Here is my project details (Message from the customer): "
            + txtProjectBrief.Value
            + "</p><p>Thank you</p>"
            + name
            ;
        //call the email function
        message = Config.SendMail(subject, body);
       
        if (message == null)
            lblMessage.InnerText = "Email sent succefully.";
        else
            lblMessage.InnerText = "Sorry, your email was not sent to the sender. Please try again.";
       
        //show the email successfull message
        lblMessage.InnerHtml = message;

    }

Troubleshoot godaddy website error messages
If the MailServer host name is wrong it shows error:
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 202.xx.xx.xx:80
If the user credentials are used, it shows error:
the remote certificate is invalid according to the validation procedure
If EnableSsl is used it shows error:
server does not support secure connection

Tuesday, 4 March 2014

Web hosting error: Request for the permission of type 'System.Security

Scenario:
I have created a web app using visual studio 2013 and it was showing error message
Server Error in '/' Application.
--------------------------------------------------------------------------------

Security Exception 
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Solution:
In web.config adding the following line worked for me:
<system.web>
    <trust level="Full" originUrl="" />
  </system.web>

Monday, 3 March 2014

HTML: Vertical line

Put a div around the markup where you want the line to appear to next and use CSS to style it:

<div class="verticalLine">

some other content

</div>
in CSS:

.verticalLine {
    border-left: thick solid #ff0000;
}

<hr width = "2" size="100" >

Simple, just place that HR, but make it very short, then very HIGH.

type: pipeline |
<td><a href="http://www.twitter.com" target="_blank">twitter</a>&nbsp;|&nbsp;</td>