To bind text change json value

  $("#txtUserID").change(function () {
                var url = "http://localhost:61200/api/Login/" + $("#txtUserID").val();
                $.ajax({
                    dataType: "json",
                    url: url,
                    success: function (response) {

                        $("#ddlBranch").select2("val", response.BRANCH);
                        $("#txtUserName").val(response.USER_NAME);
                        console.log(response);
                    }
                });
            });

To bind API json result bind in dropdownlist

  void fillBussinessUnit()
          {
              HttpResponseMessage response = client.GetAsync("api/BusinessUnit").Result;  // Blocking call!
              if (response.IsSuccessStatusCode)
              {

                  var result = response.Content.ReadAsAsync<IEnumerable<GEN_BUSINESS_UNIT>>().Result;
                  ddlBussinessUnit.DataSource = result.ToList();
                  ddlBussinessUnit.DataValueField = "CODE";
                  ddlBussinessUnit.DataTextField = "DESC_ENG";
                  ddlBussinessUnit.DataBind();
             

              }
              else
              {
               
              }
          }

How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
        config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
    }
}

Email campaign save databse

  protected void btn_Save_Click1(object sender, EventArgs e)
        {
            String fileName ="";
            Attachment atcmt = null;
            if (FileUpload1.HasFile)
            {
                fileName = SaveFile(FileUpload1.PostedFile);
                atcmt = new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName);
            }

            List<String> ToAddresses = txt_To.Text.Trim().Split(',').ToList();
            String Subject = txt_Subject.Text.Trim();
            String Content = txt_Content.Text.Trim();
            DateTime CreatedDates=DateTime.Now;

            AddEmailCampaign(ToAddresses, Subject, Content, fileName, CreatedDates);

            Thread thread = new Thread(() => Common.SendEmailCampaign(ToAddresses, Subject, Content, atcmt));
            thread.Start();
         
            txt_To.Text = "";
            txt_Content.Text = "";
            txt_Subject.Text = "";
            lblMessage.Text = "Your Message Successfully Send.";
            lblMessage.Visible = true;

        }

        #region Add_Email_Campaign

        void AddEmailCampaign(List<string> ToAddresses, string Subject, string Content, string filename, DateTime CreatedDates)
        {
                   
            CRMEntities dc = new CRMEntities();

            tbl_EmailCampaign tbl = new tbl_EmailCampaign();
            //What is the LINQ way to join a string array
            tbl.Toaddress = String.Join(",", ToAddresses.ToArray()); // To Split The Array
            tbl.Subject = Subject;
            tbl.Contents = Content;
            tbl.Attachments = filename;
            tbl.CreatedDate = CreatedDates;
            dc.tbl_EmailCampaign.AddObject(tbl);
            dc.SaveChanges();

                     
        }
        #endregion
        #region Attachmentsave

        String  SaveFile(HttpPostedFile file)
        {
            // Specify the path to save the uploaded file to.
            string savePath = "Attachments";

            // Get the name of the file to upload.
            string fileName =   DateTime.Now.Ticks+ FileUpload1.FileName;

            // Create the path and file name to check for duplicates.
            string pathToCheck = savePath+ "//" + fileName;

            // Create a temporary file name to use for checking duplicates.
            string tempfileName = "";

            // Check to see if a file already exists with the
            // same name as the file to upload.

            if (System.IO.File.Exists(pathToCheck))
            {
                int counter = 2;
                while (System.IO.File.Exists(pathToCheck))
                {
                    // if a file with this name already exists,
                    // prefix the filename with a number.
                    tempfileName = counter.ToString() + fileName;
                    pathToCheck = savePath + tempfileName;
                    counter++;
                }

                fileName = tempfileName;

                // Notify the user that the file name was changed.
                //UploadStatusLabel.Text = "A file with the same name already exists." +
                //    "<br />Your file was saved as " + fileName;
            }
            else
            {
                // Notify the user that the file was saved successfully.
                UploadStatusLabel.Text = " ";
            }

            // Append the name of the file to upload to the path.
            savePath +="//"+ fileName;
            savePath = Server.MapPath(savePath);
            // Call the SaveAs method to save the uploaded
            // file to the specified directory.
            FileUpload1.SaveAs(savePath);
            return fileName;
        }

        #endregion

   #region SendEmailCampaign

         public static void SendEmailCampaign(List<string> toAddresses, string subject, string messageBody,Attachment  attachments)
        {
            string from = (null != ConfigurationManager.AppSettings["emailSenderId"])
               ? ConfigurationManager.AppSettings["emailSenderId"].ToString() : "";
            string smtpServer = (null != ConfigurationManager.AppSettings["smtpServer"])
               ? ConfigurationManager.AppSettings["smtpServer"].ToString() : "";
            int port = (null != ConfigurationManager.AppSettings["smtpPort"])
               ? Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]) : 0;
            string userName = (null != ConfigurationManager.AppSettings["smtpUserName"])
               ? ConfigurationManager.AppSettings["smtpUserName"].ToString() : "";
            string password = (null != ConfigurationManager.AppSettings["smtpPassword"])
               ? ConfigurationManager.AppSettings["smtpPassword"].ToString() : "";

            try
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(from);
                foreach (var item in toAddresses)
                {
                    mail.To.Add(item);
                }
                if (attachments != null) mail.Attachments.Add(attachments);
                mail.Subject = subject;
                mail.Body = messageBody;
                mail.IsBodyHtml=true;
                SmtpClient SmtpServer = new SmtpClient(smtpServer);
                SmtpServer.Port = port;
                SmtpServer.Host = (null != ConfigurationManager.AppSettings["smtpHost"])
               ? ConfigurationManager.AppSettings["smtpHost"].ToString() : "";
                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
                SmtpServer.EnableSsl = true;
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                //LogException("Common.cs", "SendMail", ex.Message);
            }

        }

        #endregion



Webconfig
 <appSettings>
 <add key="smtpHost" value="smtp.gmail.com" />
    <add key="smtpPort" value="587" />
   <add key="smtpUserName" value="sample.smtpmail@gmail.com" />
    <add key="smtpPassword" value="123" />
    <add key="emailSenderId" value="sample.smtpmail@gmail.com" />
    <add key="emailReceverId" value="sample.smtpmail@gmail.com" />
    <add key="smtpServer" value="sample.smtpmail@gmail.com" />
  </appSettings>

how to value retrive in link button

 <asp:LinkButton runat ="server" CssClass ="btn" ID ="lnkapply" OnClick="lnkapply_Click" Text ="Apply" CommandArgument='<%# Eval("CareerID") %>'  ></asp:LinkButton>


 protected void lnkapply_Click(object sender, EventArgs e)
        {
          LinkButton aply = (LinkButton)sender;
          var apply= aply.CommandArgument;
          ViewState["applyview"] = apply;
          mvCareer.ActiveViewIndex = 0;
        }

Create Captcha in asp.net

page Top
*************

 <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>


Design
**************

<recaptcha:RecaptchaControl ID="recaptchaCareerRegister" runat="server" PublicKey="6Lcl_eoSAAAAAC6g52dR66NO0r3U8HFChi9TobNC"
                            PrivateKey="6Lcl_eoSAAAAABzQRMPZjmWzL0PJjfCVCpJAoj1K"  Theme="clean" />


code page
**************


  recaptchaCareerRegister.Validate();
            if (!recaptchaCareerRegister.IsValid)
            {
                txtBriefDescription.Text = txtBriefDescription.Text;              
                Lblerror.Text = "Invalid Captcha Value. Try Again..";
                Lblerror.Visible = true;
            }
            else
            {

            }

jQuery UI MultiSelect Widget

Basic 

Both multiselects are created with the following one-liner. Optgroup support is built in out of the box:
$(function(){
   $("select").multiselect(); });


Url :http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/

How to save database using EF

on Button click()
  AddEmailCampaign(ToAddresses, Subject, Content, FileUpload1.FileName,CreatedDates);

then,

 void AddEmailCampaign(List<string> ToAddresses, string Subject, string Content, string filename, DateTime CreatedDates)
        {
                   
            CRMEntities dc = new CRMEntities();

             tbl_EmailCampaign tbl = new tbl_EmailCampaign();

            //What is the LINQ way to join a string array

            tbl.Toaddress = String.Join(",", ToAddresses.ToArray()); // To Split The Array
            tbl.Subject = Subject;
            tbl.Contents = Content;
            tbl.Attachments = filename;
            tbl.CreatedDate = CreatedDates;
            dc.tbl_EmailCampaign.AddObject(tbl);
            dc.SaveChanges();
                     
        }

Search This Blog

Arsip Blog

Powered by Blogger.

Recent

Comment

Author Info

Like This Theme

Popular Posts

Video Of Day

Sponsor

Most Popular