Translate

Wednesday 25 October 2017

autocomplete feature in text box Turning off

Solution : 1

<asp:TextBox Runat="server" ID="txtUserName" placeholder="Enter User Name"  autocomplete="off"></asp:TextBox>


Solution : 2

< script src = "Scripts/jquery-1.6.4.min.js" > < /script> < script type = "text/javascript" > 
    $(document).ready(function() 
    { 
        $("#<%=txtUserName.ClientId %>").attr('autocomplete', 'off'); 
    }); 
//document.getElementById("<%=txtUserName.ClientID %>").autocomplete = "off" ;
< /script> 


<asp:TextBox Runat="server" ID="txtUserName" placeholder="Enter User Name"></asp:TextBox>



Solution : 3

Asp design page 

<asp:TextBox Runat="server" ID="txtUserName" placeholder="Enter User Name"></asp:TextBox>

C# Class file 
-----------------
protected void Page_Load(object sender, EventArgs e) 

   
 txtUserName.Attributes.Add("autocomplete", "off"); 
   


Saturday 21 October 2017

Best Error message show in web/windows application.

There are four rules to be follow to give a error message to user while their is a error in your application These are as follows.
  • The error message needs to be short and meaningful.
  • The placement of the message needs to be associated with the field.
  • The message style needs to be separated from the style of the field labels and instructions.
  • The style of the error field needs to be different than the normal field
Like:
There was a problem to retrieving the XML data : node not available x000000x123

Wednesday 11 October 2017

How to restrict file type in FileUpload control in asp.net

 <asp:FileUpload ID="fuSignature" runat="server" />
                <asp:RegularExpressionValidator ID="RegExValFileUploadFileType" runat="server"
                        ControlToValidate="fuSignature"
                        ErrorMessage="Only .jpg,.png,.jpeg,.pdf files are allowed" ForeColor="Red"
                        Font-Size="Medium"
                        ValidationExpression="(.*?)\.(jpg|jpeg|png|pdf|JPG|JPEG|PNG|PDF)$"></asp:RegularExpressionValidator>




OR

 protected void BtnSave_Click(object sender, EventArgs e)
    {
        if (fuSignature.HasFile)
        {
            string fileExtension =
               System.IO.Path.GetExtension(fuSignature.FileName);

           if (fileExtension.ToLower()   == ".jpeg" || fileExtension.ToLower()   == ".jpg" || fileExtension.ToLower()  == ".pdf")
            {
                // do ur work like save file
            }
            else
            {
               lblMeaasge.Text = "Only .jpeg,.jpg,.pdf file allow";
            }
        }
        else
        {
            lblMeaasge.Text = "Please Upload File";
        }
    }

Monday 9 October 2017

read-only property in calendar extender text box in asp.net.


Readonly property in calendar extender text box in asp.net.

while we use readonly true in asp textbox the value can not be assign or save in my data base. For this issue just put the textbox in the page load and
assign by this way so that the issue is fixed.

 protected void Page_Load(object sender, EventArgs e)
      {
    txtOrderDate.Attributes.Add("readonly", "readonly");
 if (!IsPostBack)
        {
        }


      }

Download file when clicking on the anchor tag link (instead of navigating to the file)

Download file when clicking on the anchor tag link (instead of navigating to the file)

<a href="Documents/Resume/pabitraResume.pdf" download>Download</a>  

Reset All Asp.net control or Clear All Page Control

Reset All Asp.net control or Clear All Page Control
---------------------------

use this
-----------------

 protected void btnReset_Click(object sender, EventArgs e)
 {
Control[] controls = { btnSubmit,txtName,ddlCountry,hfCountryID,lblCityName,chkYes,chkNo };
                    ClearAllFormControl(controls); 
}

void ClearAllFormControl(Control[] controls)
          {

        foreach (Control c in controls)
        {
            switch (c.GetType().ToString())
            {
                case "System.Web.UI.WebControls.Button":
                    {
                        //((Button)c).Text = "Submit";
                    } break;
                case "System.Web.UI.WebControls.TextBox":
                    {
                        ((TextBox)c).Text = string.Empty;
                    } break;
                case "System.Web.UI.WebControls.DropDownList":
                    {
                        if (((DropDownList)c).SelectedIndex > 0) ((DropDownList)c).SelectedIndex = 0;
                    } break;
                case "System.Web.UI.WebControls.HiddenField":
                    {
                        ((HiddenField)c).Value = string.Empty;
                    } break;
                case "System.Web.UI.WebControls.Label":
                    {
                        ((Label)c).Text = string.Empty;
                    } break;
                case "System.Web.UI.WebControls.CheckBox":
                    {
                        ((CheckBox)c).Checked = false;
                    } break;

            }


        }
    }




OR
___________






// use this namespace : using System.Web.UI.WebControls;

 void ClearAllPageControl()
    {
        Control[] controllist = { ddlTypeofUpdating, txtOrderNo, txtOrderDate, txtDescription, fuOrderCopy, hfOrderCopy, hfOrderId };
        foreach (Control control in controllist)
        {
            if (control is TextBox)
            {
                TextBox textBox = (TextBox)control;
                textBox.Text = string.Empty;
            }
            else if (control is DropDownList)
            {
                DropDownList ddl = (DropDownList)control;
                if (ddl.SelectedIndex > 0)
                    ddl.SelectedIndex = 0;
            }
            else if (control is FileUpload)
            {
                FileUpload fu = (FileUpload)control;
                fu = null;
            }
            else if (control is HiddenField)
            {
                HiddenField hf = (HiddenField)control;
                hf.Value = "0";
            }
        }
    }