Monday, 18 March 2013

Add favriate

<div class="rightFavourite" id="addbtnDiv" runat="server">
    <a href="javascript:;" class="addFavourite" onclick="javascript:addToCompare();">Add to Favourite</a></div>
<asp:HiddenField ID="hdnPageUrl" runat="server" />
<asp:HiddenField ID="hdnPageTitle" runat="server" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserControls_UCaddFvrtBtn : System.Web.UI.UserControl
{
    FavouritePages.clFvrtPg objClFvrtPg = new FavouritePages.clFvrtPg();

    protected void Page_Load(object sender, EventArgs e)
    {
        hdnPageUrl.Value = HttpContext.Current.Request.Url.ToString();
        hdnPageTitle.Value = this.Page.Title.ToString();
        checkPageExits();
    }
    public void checkPageExits()
    {
        string pageUrl = HttpContext.Current.Request.Url.ToString();
        string pageTitle = this.Page.Title.ToString();

        DataTable _dtFvrtPg = objClFvrtPg.dtFavouritePages;
        if (_dtFvrtPg != null)
        {
            if (_dtFvrtPg.Rows.Count > 0)
            {
                foreach (DataRow dr in _dtFvrtPg.Rows)
                {
                    if (pageUrl == dr["PageUrl"].ToString() && pageTitle == dr["PageTitle"].ToString())
                    {
                        addbtnDiv.Attributes.Add("style", "display:none");
                    }                 
                }
            }
        }
    }
}

Tuesday, 5 March 2013

Request UrlReferrer

 if (Request.UrlReferrer == null)
            {
}


<script language="JavaScript" type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }

    </script>

<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

Thursday, 28 February 2013

Replace junk charater function

public string cleanip(string str)
    {
        string str_op;
        str_op = str;
        if (str_op != "" && str_op != null)
        {
            str_op = str_op.Replace("<", "");
            str_op = str_op.Replace(">", "");
            str_op = str_op.Replace("&lt;", "");
            str_op = str_op.Replace("&gt;", "");
        }
        if (str_op != null)
        {
            if (str_op.Length >= 50)
                str_op = str_op.Remove(50);
        }
        return str_op;
    }

Monday, 25 February 2013

validation with ajax filter

  
 <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" autocomplete="off"  TabIndex="15"></asp:TextBox>
                                    </div>
                                    <div class="errormsg_contact">
                                        <asp:RequiredFieldValidator ID="rfvYourMessage" runat="server" ControlToValidate="txtMessage"
                                Display="Dynamic" ErrorMessage="Please enter your message" ValidationGroup="SUBMIT"
                                SetFocusOnError="true"> </asp:RequiredFieldValidator>

                                <cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" runat="server"
                                FilterType="Custom, Numbers, UppercaseLetters, LowercaseLetters" ValidChars=" ,./\()_" TargetControlID="txtMessage"> </cc1:FilteredTextBoxExtender>

                                        <asp:RegularExpressionValidator ID="rvtxtMessage" runat="server" ControlToValidate="txtMessage"
                                Display="Dynamic" ErrorMessage="Message contains minuman 5 maximum 1000 characters with or without space"
                                ValidationExpression="[,./\()_-a-zA-z0-9 ]{5,1000}" ValidationGroup="SUBMIT"
                                SetFocusOnError="true" />

Sunday, 17 February 2013

validation more than zero

 function fnChkNumVal(source, args) {
            //var iknum = parseInt(args.Value)
            var iknum =args.Value
            if(iknum==0)
                 args.IsValid = false;
            else
                 args.IsValid = true ; 
        }

 <asp:TextBox ID="txtNWOnlineTransAmt" MaxLength="16" runat="server" CssClass="input">

  <asp:CustomValidator ID="CustomValidator19" runat="server" ErrorMessage="Transaction amount can not be zero"
                                                    EnableClientScript="true" SetFocusOnError="true" ClientValidationFunction="fnChkNumVal"
                                                    ControlToValidate="txtNWOnlineTransAmt" ValidationGroup="Feedback" Display="None"
                                                    CssClass="commment"></asp:CustomValidator>

Friday, 11 January 2013

validation

40280914/05/930   mayur 420------bhushan 929
d133028
b131816
sainathom
SelectedValue=
-------------------------------------------------------------------------------
gaurav rnd date funtion

DateTime.Parse(strinput);
            string[] arr = strinput.Split('/');
            string strNewDate = arr[1] + "/" + arr[0] + "/" + arr[2];

            string strRegex = @"^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$"; // dd/mm/yyyy
            //@"^([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$"; // MM/dd/yyyy

            Regex re = new Regex(strRegex);

            if (re.IsMatch(strNewDate))
                return (true);
            else
                return (false);
------------------------------------------------------------------------------
[0-9a-zA-Z :]*
.+.(P|p)(D|d)(F|f)$        for pdf file
[^<>]{5,8000}
regular expression allowing alphabets and spaces only

 1 Numbers only regular expression (0-9 regex) – ^[0-9]*$
 2 Decimal numbers with 2 floating point compulsory regular expression (0-9 with decimal) – ^([0-9]*)(\.[0-9]{2})?$
 3 Alphabets only regular expression () – ^[a-zA-Z]*$
 4 Alphanumeric string regular expression – ^[a-zA-Z0-9]*$
 5 Alphanumeric and white space regular expression – ^[a-zA-Z0-9 ]*$

([0-0]{1}[1-9]{1}[0-9]{9})|[1-9]{1}[0-9]{9}  mobile 10 or 11
(?([1-9]{1})?([0]{1}[1-9]{1})?([0-9]{9})   for javascript
 setfocusonerror="true" 

^[!@#$%*()/_+=^&amp;{}|\[\]:;&amp;quot;?.,\'\s`\-~a-zA-z0-9]{2,300}$         commnet  -----------no reload-------------------
   <script type="text/javascript" language="javascript" >

        window.history.forward();

        function noBack() {

            window.history.forward();

        }

    </script>
  
    </head>
    <body onload="noBack();" onpageshow="if(event.persisted) noBack();" onunload="">
-----------------------------------c sharp------
 static bool IsValid(string value)
    {
    return Regex.IsMatch(value, @"^[a-zA-Z0-9]*$");
    }


Regex regex = new Regex(@"\d+");
    Match match = regex.Match("Dot 55 Perls");
    if (match.Success)
    {
        Console.WriteLine(match.Value);
    }
Regex a1 = new Regex(@"^\s+", RegexOptions.Compiled);
Regex a2 = new Regex(@"\s+$", RegexOptions.Compiled);

foreach (object item in _collection) // Example loop.
{
    //
    // Reuse the compiled regex objects over and over again.
    //
    string source = "  Some text ";
    source = a1.Replace(source, "");
    source = a2.Replace(source, ""); // compiled: 3620
}
-----------------------------------------
const string example = @"This string
has two lines";

    // Get a collection of matches with the Multiline option.
    MatchCollection matches = Regex.Matches(example, "^(.+)$", RegexOptions.Multiline);
    Regex regex = new Regex("dotnet.*");
    Console.WriteLine(regex.IsMatch("dotnetperls")); // True
    //
    // Zero or more s letters are allowed.
    //
    regex = new Regex("perls*");
    Console.WriteLine(regex.IsMatch("perl")); // True
    Console.WriteLine(regex.IsMatch("perlssss")); // True
    Console.WriteLine(regex.IsMatch("pert")); // False
    //
    // Use the star with a parentheses grouping.
    // ... Also use the $ sign to signal the terminal.
    //
    regex = new Regex("sam(abc)*$");
    Console.WriteLine(regex.IsMatch("samabcabc")); // True
    Console.WriteLine(regex.IsMatch("sam")); // True
    Console.WriteLine(regex.IsMatch("samab")); // False
-----------------------------------------
static string CollapseSpaces(string value)
    {
    return Regex.Replace(value, @"\s+", " ");
    }

    static void Main()
    {
    string value = "Dot  Net  Perls";
    Console.WriteLine(CollapseSpaces(value));
    value = "Dot  Net\r\nPerls";
    Console.WriteLine(CollapseSpaces(value));
    }

-----------------------------------------
static void Main()
    {
    // 1
    // The string you want to change.
    string s1 = "This string has something at the end<br/>";

    // 2
    // Use regular expression to trim the ending string.
    string s2 = System.Text.RegularExpressions.Regex.Replace(s1, "<br/>$", "");

    // 3
    // Display the results.
    Console.WriteLine("\"{0}\"\n\"{1}\"",
        s1,
        s2);


const string input = "There are 4 numbers in this string: 40, 30, and 10.";
    // Split on one or more non-digit characters.
    string[] numbers = Regex.Split(input, @"\D+");
    foreach (string value in numbers)
    {
        if (!string.IsNullOrEmpty(value))
        {
        int i = int.Parse(value);
        Console.WriteLine("Number: {0}", i);
        }
    }




    }
his string has something at the end
-----------------------------------------

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
    // Input strings.
    const string s1 = "samuel allen";
    const string s2 = "dot net perls";
    const string s3 = "Mother teresa";

    // Write output strings.
    Console.WriteLine(TextTools.UpperFirst(s1));
    Console.WriteLine(TextTools.UpperFirst(s2));
    Console.WriteLine(TextTools.UpperFirst(s3));
    }
}

public static class TextTools
{
    /// <summary>
    /// Uppercase first letters of all words in the string.
    /// </summary>
    public static string UpperFirst(string s)
    {
    return Regex.Replace(s, @"\b[a-z]\w+", delegate(Match match)
    {
        string v = match.ToString();
        return char.ToUpper(v[0]) + v.Substring(1);
    });
    }
}

Output

Samuel Allen
Dot Net Perls
Mother Teresa

-------------------------------------------

public int PageNumber
    {
        get
        {
            if (ViewState["PageNumber"] != null)
                return Convert.ToInt32(ViewState["PageNumber"]);
            else
                return 0;
        }
        set
        {
            ViewState["PageNumber"] = value;

        }
    }

  var filter2 =/^\(?([6-9]{2})?([6-9]{1})?([0-9]{10})$/

    if (document.getElementById("txtmobileno").value!= "")
    {

                if (filter2.test(document.getElementById("txtmobileno").value))
            {
               
            }
            else
            {
                inlineMsg('txtmobileno','The Mobile No. length should be  10 or 12 characters.',7);
                document.getElementById("txtmobileno").value="";
                document.getElementById("txtmobileno").focus();
                return false;
             }
   
    }

  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;       
            if(reg.test(document.getElementById("txtname").value) == false)
            {        
               inlineMsg('txtname','Please enter a valid email id. You will login to your account using this ID.',7);
             document.getElementById("txtname").focus();
              return false;
            }




function ValidateCheckBox(sender, args) {
            if (document.getElementById("<%=chkTerms.ClientID %>").checked == true) {
                args.IsValid = true;
            } else {
                args.IsValid = false;
            }
        }
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required Terms and Conditions"
                                ClientValidationFunction="ValidateCheckBox"></asp:CustomValidator>





  function ValidateFile(sender, args)
     {
   
            if (document.getElementById("<%=fileREsume.ClientID%>").value == "")
         {
                args.IsValid = true;
         }
         else
          {
           
                 var file = document.getElementById('<%=fileREsume.ClientID %>');
                var len=file.value.length;
                var ext=file.value;
          
               if(len > 3)
               
                 {
              
                     if((ext.substr(len-3,len)=="doc")||(ext.substr(len-3,len)=="DOC"))
                    {
                      args.IsValid = true;
                    } else
                     if((ext.substr(len-3,len)=="rtf")||(ext.substr(len-3,len)=="RTF"))
                    {
                      args.IsValid = true;
                    } else
                     if((ext.substr(len-3,len)=="ocx")||(ext.substr(len-3,len)=="OCX"))
                    {
                      args.IsValid = true;
                    }
                     else
                     {
                     args.IsValid = false;
                    }
                }
          
              
            }
        }

Wednesday, 9 January 2013

merge two table in one table

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class TAT_merge2tablein1table : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    public int totalcount_3;
    protected void Page_Load(object sender, EventArgs e)
    {
        // string domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
        // string[] paramsLogin = domainUser.Split('\\');
        //Response.Write( paramsLogin[0].ToString());
        BindUserAccounts();
    }

    private void BindUserAccounts()
    {
        OfferDetails _OfferDetails = new OfferDetails();

        _OfferDetails._OfferDetailsCardId = "24";
        //this.CategotynameToMatch; "
        // SqlDataAdapter da = new SqlDataAdapter("select username,lastname from UserProfile ", con);
        ds = _OfferDetails.GetOfferDetails_AllFilter();
        int totalcount_1 = ds.Tables[0].Rows.Count;
        int totalcount_2 = ds.Tables[1].Rows.Count;
        totalcount_3 = totalcount_1 + 1;

        DataTable dt = new DataTable();
        DataColumn colString = new DataColumn("Categoryname");
        colString.DataType = System.Type.GetType("System.String");
        dt.Columns.Add(colString);

        DataColumn colString1 = new DataColumn("Categoryid");
        colString1.DataType = System.Type.GetType("System.String");
        dt.Columns.Add(colString1);

        //DataRow dataRow = dt.NewRow();
        //dataRow["Categoryname"] = "Dining";
        //dataRow["Categoryid"] = "8";
        //dt.Rows.Add(dataRow);

        // Dim i As Integer = 0
        //Dim table As DataTable = ds.Tables(0)
        //table.Columns.Add(New DataColumn("no", GetType(Integer)))
        //Dim rowcount As Integer = table.Rows.Count
        //Dim k As Integer = 1
        //While (i < rowcount)
        //    table.Rows(i)("no") = k
        //    i = i + 1
        //    k = k + 1

        //End While
        int i = 0;
        DataTable dt1 = ds.Tables[0];
        int rowcount = dt1.Rows.Count;
        int k = 1;
        DataTable dt2 = ds.Tables[1];
        int rowcount2 = dt2.Rows.Count;


        foreach (DataRow dr in dt1.Rows)
        {
            DataRow lLang = dt.NewRow();
            lLang["Categoryname"] = dr["CategotyName"].ToString();
            lLang["Categoryid"] = dr["pkCatId"].ToString();
            dt.Rows.Add(lLang);
        }
        foreach (DataRow dr in dt2.Rows)
        {
            DataRow lLang = dt.NewRow();
            lLang["Categoryname"] = dr["CategotyName"].ToString();
            lLang["Categoryid"] = dr["pkCatId"].ToString();
            dt.Rows.Add(lLang);
        }

        GridView1.DataSource = dt;
        GridView1.DataBind();

    }


}