Sunday, 29 September 2013

Prevent to web serveice on browser url in asp.net

in web.config file
- <system.web>
    <customErrors mode="On" defaultRedirect="~/CustomeErrorPage.aspx?"/>
<!--<sessionState mode="InProc" cookieless="false" timeout="15"/>-->
    <pages validateRequest="false"></pages>
    <webServices>
      <protocols>
        <remove name="Documentation" />
      </protocols>
    </webServices>
  </system.web>

Prevent show previous pages after logout in asp.net

protected void logout_OnClick(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("login.aspx");
}

on master page -

protected void Page_Init(object sender, EventArgs e
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
}

Friday, 27 September 2013

Ajax Please wait image using update panel in asp.net c#

<asp:UpdateProgress ID="UpdateProgress" runat="server">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="~/Images/loading.gif" AlternateText="Processing" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>

<asp:ModalPopupExtender ID="modalPopup" runat="server" TargetControlID="UpdateProgress"
PopupControlID="UpdateProgress" BackgroundCssClass="ModalPopupBG" />

<script type="text/javascript">
    //*****************************Model popup (Please wait)****************

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
    function BeginRequestHandler(sender, args) {
        var popup = $find('<%= modalPopup.ClientID %>');
        if (popup != null) {
            popup.show();
        }
    }

    function EndRequestHandler(sender, args) {
        var popup = $find('<%= modalPopup.ClientID %>');
        if (popup != null) {
            popup.hide();
        }
    }

</script>

Fill dropdownlist using Cashcading style sheet in asp.net

HTML-- without parent id

<asp:DropDownList ID="ddl_block" runat="server"  >  </asp:DropDownList>

<asp:CascadingDropDown ID="Cascadingddl_block" runat="server" Category="SubDistrict" TargetControlID="ddl_block" LoadingText="Loading SubDistrict..." PromptText="---Select---" ServiceMethod="BindSubDitstrictdropdown" ServicePath="~/DropdownWebService.asmx"> </asp:CascadingDropDown>

WebService-

 [WebMethod(EnableSession = true)]
    public CascadingDropDownNameValue[] BindStatedropdown(string knownCategoryValues, string category)
    {

        StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        DataTable dtSelectMethod = new DataTable();
        dtSelectMethod = Select_All_Data("mstAState", "*", "Active='1'", "StateName", "ASC");
        int Index = 0;
        List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
        foreach (DataRow dtstaterow in dtSelectMethod.Rows)
        {
            string StateCode = dtstaterow["StateCode"].ToString();
            string StateName = dtstaterow["StateName"].ToString();
            statedetails.Add(new CascadingDropDownNameValue(StateName, StateCode));
        }
        return statedetails.ToArray();
    }                    


HTML-- with parent id

<asp:DropDownList ID="ddl_block" runat="server" ></asp:DropDownList>

<asp:CascadingDropDown ID="Cascadingddl_block" runat="server" Category="SubDistrict" TargetControlID="ddl_block" LoadingText="Loading SubDistrict..." PromptText="---Select---" ServiceMethod="BindSubDitstrictdropdown" ServicePath="~/DropdownWebService.asmx"   ParentControlID="ddl_district"> </asp:CascadingDropDown>


[WebMethod(EnableSession = true)]
    public CascadingDropDownNameValue[] BindClusterdropdown(string knownCategoryValues, string category)
    {
        string StateCode;
        StringDictionary StateCodedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        StateCode = Convert.ToString(StateCodedetails["State"]);
        
        string clusternames = null;
        string clus = Session["clustercheck"].ToString();
        if (clus != "")
        {
            if (clus.Length == 6)
            {
                clusternames = "'" + clus + "'";
            }
            else
            {
                // clusternames = clus.Substring(0, clus.Length - 1);
                clusternames = clus;
            }
        }

        DataTable dtSelectMethod = new DataTable();
        string condition = "";
        if (clusternames == null)
        { condition = "StateCode='" + StateCode + "'"; }
        else { condition = " StateCode='" + StateCode + "' and ClusterCode in (" + clusternames + ") "; }
         
       // string 
        dtSelectMethod = Select_All_Data("mstBCluster", "*", condition, "ClusterName", "ASC");

        List<CascadingDropDownNameValue> regiondetails = new List<CascadingDropDownNameValue>();
        foreach (DataRow dtregionrow in dtSelectMethod.Rows)
        {
            string ClusterCode = dtregionrow["ClusterCode"].ToString();
            string ClusterName = dtregionrow["ClusterName"].ToString();
            regiondetails.Add(new CascadingDropDownNameValue(ClusterName, ClusterCode));

        }
        return regiondetails.ToArray();
    }

             

Check string array [] value with Javascript

using script-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">

function checkusername(value) {
 
    var codes = ['admin', 'adm', 'administrator', 'cluster', 'clu'];
     
        if ($.inArray(value.toLowerCase(), codes) > -1) {          
            alert("Invalid userid ! Please try another");
            return false;
        }

Password strong with Jquery (Atleast-1 numeric ,1 lower case,1 upper case, 1 special character)

function checkPwd(str) {
       // alert("enter");
        var msg = "";
        if (str.length < 8) {
            msg += 'Minimum 8 character'; //  for min length
        } else if (str.length > 20) {
            msg += 'Maximum 20 character'; //  for max length
        } else if (str.search(/\d/) == -1) {
            msg += '- Atleast one numeric'; // for numeric
        } else if (str.search(/[a-z]/) == -1) {
            msg += '- Atleast one Lower case letter'; // for character
        } else if (str.search(/[A-Z]/) == -1) {
            msg += '- Atleast one upper case letter'; // for character
        } else if (str.search(/[^a-zA-Z0-9\<\>\@\#\=\.\_\-\!\$]/) != -1) {
            msg += '- Password invalid ! Atleast one special character also(<,>,@,#,=,.,_,-,!,$])'; // for special character;
        }
        if (msg != "") {
         
            alert(msg);
            return false;
        }
        else { return true; }
    }

Strong Password with regular expression in asp.net c#

Atleast 1-lower,1-upper,1-numeric,1-special character

public static string checkpasswordCharacters(string password)
    {
        string msg = "";      
        Regex len = new Regex("^.{6,15}$");
        Regex num = new Regex("\\d");
       // Regex alphaL = new Regex("\\D");
        Regex alphaL = new Regex("[a-z]");
        Regex alphaU = new Regex("[A-Z]");
        Regex special = new Regex("[><#@=._!$-]");

        if (!len.IsMatch(password) )
        {
            msg += "-Minimum password length is 6 characters \\n";
        }
        if (!num.IsMatch(password))
        {
            msg += "-Please enter atleast one numeric value \\n";
        }
        if (!alphaL.IsMatch(password))
        {
            msg += "-Please enter atleast one lower case alphabet \\n";
        }
        if (!alphaU.IsMatch(password))
        {
            msg += "-Please enter atleast one upper case alphabet \\n";
        }
        if (!special.IsMatch(password))
        {
            msg += "-Please enter atleast one special Character \\n";
        }
       
        return msg;      

    }

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...