How to call a WebMethod of a Web Service using jQuery Ajax JSON?
How to call a WebMethod of a Web Service using jQuery Ajax JSON
The following jQuery is used to call a WebMethod of a Web Service using jQuery Ajax JSON.jQuery:
- $(document).ready(function () {
- var Name = $("#name").val();
- var Email = $("#email").val();
- var Message = $("#msg").val();
- $.ajax({
- type: "POST",
- data: "{'Name':'" + Name + "','Email':'" + Email + "','Message':'" + Message + "'}",
- url: "/WebServices/WS.asmx/Contact",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (response) {
- if (response.d == true) {
- alert("Thank you for contacting JJ Technology Solutions.");
- }
- else {
- alert("Error sending email. Please try again later.");
- }
- }
- });
- });
How to find the value of a HTML tag attribute using jQuery?
Note:
When using "jquery.selectbox.js" plugin the "select & option" tags will be converted into "ul li" at run time. The problem is we can not get the selected value using the normal jQuery or Javascript when we use this plugin. The following solution rectifies this situation.Here we are going to find the 'rel' attribute value of an anchor tag which is the selected option.
HTML:
- <fieldset class="sapDD medium">
- <span class="required">*</span>
- <select id="Division" name="Division" sb="37042751" style="display: none;">
- <option value="">Select a Division</option>
- <option value="example1@gmail.com" selected="selected">example1</option>
- <option value="example2@gmail.com">example2</option>
- <option value="example3@gmail.com">example3</option>
- <option value="example4@gmail.com">example4</option>
- </select>
- <div id="sbHolder_37042751" class="sbHolder" tabindex="0">
- <a id="sbToggle_37042751" href="#" class="sbToggle"></a>
- <a id="sbSelector_37042751" href="#" class="sbSelector">example1</a>
- <ul id="sbOptions_37042751" class="sbOptions" style="top: 16px; max-height: 583px; display: none;">
- <li><a href="#" rel="" class="">Select a Division</a></li>
- <li><a href="#example1@gmail.com" rel="example1@gmail.com" class="">example1</a></li>
- <li><a href="#example2@gmail.com" rel="example2@gmail.com">example2</a></li>
- <li><a href="#example3@gmail.com" rel="example3@gmail.com">example3</a></li>
- <li><a href="#example4@gmail.com" rel="example4@gmail.com">example4</a></li>
- </ul>
- </div>
- </fieldset>
jQuery:
- $(document).ready(function(){
- var Division = $("#Division").next(".sbHolder").find("a.sbSelector").text(); ;
- var DivisionEmail = $("#Division").next(".sbHolder").find("ul.sbOptions").find("a:contains('" + Division + "')").attr("rel");
- alert(DivisionEmail);
- });
How to insert values in SQL Server database table using Umbraco?
Required Namespaces:
- using umbraco;
- using umbraco.BusinessLogic;
- using umbraco.DataLayer;
C# Code:
- public bool InsertData(string FirstName, string LastName, string Email, string Phone)
- {
- bool IsSuccessful = false;
- try
- {
- string InsertQuery = "INSERT INTO tblPerson(FirstName, LastName, Email, Phone, CreatedDate) values ";
- InsertQuery = InsertQuery + "(@FirstName, @LastName, @Email, @Phone, @CreatedDate)";
- Application.SqlHelper.ExecuteNonQuery(InsertQuery,
- Application.SqlHelper.CreateParameter("@FirstName", FirstName),
- Application.SqlHelper.CreateParameter("@LastName", LastName),
- Application.SqlHelper.CreateParameter("@Email", Email),
- Application.SqlHelper.CreateParameter("@Phone", Phone),
- Application.SqlHelper.CreateParameter("@CreatedDate", DateTime.Now));
- IsSuccessful = true;
- }
- catch
- {
- IsSuccessful = false;
- }
- return IsSuccessful;
- }
How to send email using SMTP in ASP.Net / C#?
C#:
- public bool Send_Email(string Subject, string Body, string ToEmail, string AttachmentUrl)
- {
- bool Sent = false;
- try
- {
- if (!string.IsNullOrEmpty(ToEmail))
- {
- string FromEmail = "", Username = "", Password = "", Host = "", Port = "";
- FromEmail = Convert.ToString(ConfigurationManager.AppSettings["FromEmail"]);
- Username = Convert.ToString(ConfigurationManager.AppSettings["Username"]);
- Password = Convert.ToString(ConfigurationManager.AppSettings["Password"]);
- Host = Convert.ToString(ConfigurationManager.AppSettings["Host"]);
- Port = Convert.ToString(ConfigurationManager.AppSettings["Port"]);
- bool UseSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSsl"]);
- System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
- System.Net.NetworkCredential cred = new System.Net.NetworkCredential(Username, Password);
- if (ToEmail.Contains(','))
- {
- string[] ToEmailArray = ToEmail.Split(',');
- foreach (string si in ToEmailArray)
- {
- mail.To.Add(si);
- }
- }
- else
- {
- mail.To.Add(ToEmail);
- }
- mail.Subject = Subject;
- mail.From = new System.Net.Mail.MailAddress(FromEmail, Convert.ToString(ConfigurationManager.AppSettings["FromName"]));
- mail.IsBodyHtml = true;
- mail.Body = Body;
- if (!string.IsNullOrEmpty(AttachmentUrl))
- {
- System.Net.Mail.Attachment Attachment;
- if (AttachmentUrl.Contains(','))
- {
- string[] AttachmentUrlArray = ToEmail.Split(',');
- foreach (string url in AttachmentUrlArray)
- {
- string strUrl = Uri.EscapeUriString(url);
- if (File.Exists(strUrl))
- {
- Attachment = new System.Net.Mail.Attachment(strUrl);
- mail.Attachments.Add(Attachment);
- }
- }
- }
- else
- {
- string strUrl = Uri.EscapeUriString(AttachmentUrl);
- if (File.Exists(strUrl))
- {
- Attachment = new System.Net.Mail.Attachment(strUrl);
- mail.Attachments.Add(Attachment);
- }
- }
- }
- System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
- smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
- smtp.UseDefaultCredentials = false;
- smtp.EnableSsl = UseSsl;
- smtp.Credentials = cred;
- smtp.Host = Host;
- smtp.Port = Convert.ToInt32(Port);
- smtp.Send(mail);
- Sent = true;
- }
- }
- catch
- {
- Sent = false;
- }
- return Sent;
- }
Configuration in appSettings.config:
- <!-- Email Data Configuration Start -->
- <add key="FromName" value="Company Name or Any Text"/>
- <add key="FromEmail" value="example@gmail.com"/>
- <add key="Username" value="example@gmail.com"/>
- <add key="Password" value="password"/>
- <add key="Host" value="smtp.gmail.com"/>
- <add key="Port" value="587"/>
- <add key="UseSsl" value="true"/>
- <add key="ToEmail" value="example@gmail.com"/>
- <!-- Email Data Configuration End -->
How to enable the remote testing of webservice methods in live environment?
Scenario:
The test form is only available for requests from the local machine.Solution:
For enabling remote web service test page, just addHttpPost
/HttpGet
protocol in the webServices
section of your web.config. By default, this option is disabled to increase the security in live environment, but you can enable it in web.config as follows for debugging the deployed web services.- <webServices>
- <protocols>
- <add name="HttpGet"/>
- <add name="HttpPost"/>
- </protocols>
- </webServices>
How to resolve “HTTP Error 500.19 - Internal Server Error” on IIS
Error:
HTTP Error 500.19-Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Solution:
Step 1:
Start Visual studio command prompt as an administrator as shown in the picture below:Step 2:
In the visual studio command prompt type the command aspnet_regiis –i and then press Enter as shown in picture below:Step 3:
Installation process will take some time and once finished it will display finished installing message. After installation again refresh site in IIS and browse it again.How to find the Document Type Alias of the First Child Node using Razor?
To find the Document Type Alias of the First Child Node using Razor.
- @Model.Children.First().NodeTypeAlias