add

Tuesday, 22 April 2014

detect browser in asp.net using c#

 System.Web.HttpBrowserCapabilities browser = Request.Browser;
        string s = "Browser Capabilities\n"
            + "Type = " + browser.Type + "\n"
            + "Name = " + browser.Browser + "\n"
            + "Version = " + browser.Version + "\n"
            + "Major Version = " + browser.MajorVersion + "\n"
            + "Minor Version = " + browser.MinorVersion + "\n"
            + "Platform = " + browser.Platform + "\n"
            + "Is Beta = " + browser.Beta + "\n"
            + "Is Crawler = " + browser.Crawler + "\n"
            + "Is AOL = " + browser.AOL + "\n"
            + "Is Win16 = " + browser.Win16 + "\n"
            + "Is Win32 = " + browser.Win32 + "\n"
            + "Supports Frames = " + browser.Frames + "\n"
            + "Supports Tables = " + browser.Tables + "\n"
            + "Supports Cookies = " + browser.Cookies + "\n"
            + "Supports VBScript = " + browser.VBScript + "\n"
            + "Supports JavaScript = " +
                browser.EcmaScriptVersion.ToString() + "\n"
            + "Supports Java Applets = " + browser.JavaApplets + "\n"
            + "Supports ActiveX Controls = " + browser.ActiveXControls
                  + "\n"
            + "Supports JavaScript Version = " +
                browser["JavaScriptVersion"] + "\n";

Friday, 18 April 2014

How can I use xsl:value-of in image path

<img>
<xsl:attribute name="src>/folder/images/<xsl:value-of select="thumbnail"/></xsl:attribute>
</img>

2
<img><xsl:attribute name="src">/folder/images/<xsl:value-of select='thumbnail' /></xsl:attribute></img>

Wednesday, 18 December 2013

Display characters limit to a textbox in asp.net

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="../MaxLength.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //Normal Configuration
            $("[id*=txtpdescription]").MaxLength({ MaxLength: 1000 });

            //Specifying the Character Count control explicitly
            $("[id*=TextBox2]").MaxLength(
            {
                MaxLength: 15,
                CharacterCountControl: $('#counter')
            });

            //Disable Character Count
            $("[id*=TextBox3]").MaxLength(
            {
                MaxLength: 20,
                DisplayCharacterCount: false
            });
        });
   </script>



Create a javascript file and past below code to javascript file:



eval(function (p, a, c, k, e, d) { e = function (c) { return c }; if (!''.replace(/^/, String)) { while (c--) { d[c] = k[c] || c } k = [function (e) { return d[e] } ]; e = function () { return '\\w+' }; c = 1 }; while (c--) { if (k[c]) { p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]) } } return p } ('(6($){$.58.5=6(2){3 31={5:10,13:33,9:30};3 2=$.54(31,2);20 14.42(6(){3 4=$(14);12(2.13){12(2.9==30||2.9.11==0){3 32=\'<27 41 = "66:\'+4[0].49+\'48;47-50:51"></27>\';4.53(32)}}4.7(4.7().28(0,2.5));18(14,2.5,2.9,2.13);4.25("46",6(19){3 23=19.23?19.23:19.44;3 29=36 35(8,37,38,39,40);55(3 21=0;21<29.11;21++){12(23==29[21])20 33}20 18(14,2.5,2.9,2.13)});4.25("67",6(19){18(14,2.5,2.9,2.13)});4.25(\'62 57 56\',6(){3 24=$(14);59(6(){24.7(24.7().28(0,2.5));18(24,2.5,2.9,2.13)},63)})})}})(68);6 18(16,22,15,34){3 11=$(16).7().11;3 17=22-11;12(17<0){$(16).7($(16).7().28(0,22));17=0}12(34){12(15==30||15.11==0){15=$(16).52()}3 26=15[0].45.65();12(26=="61"||26=="27"){15.64(17+" 69"+(17>1?"60":"")+" 43.")}}20 11<=22-1}', 10, 70, '||options|var|textBox|MaxLength|function|val||CharacterCountControl||length|if|DisplayCharacterCount|this|control|t|characters|SetCharacterCount|e|return|i|maxLength|keyCode|textarea|bind|tagName|div|substring|codes|null|defaults|counter|true|isVisible|Array|new|||||style|each|left|which|nodeName|keypress|text|px|offsetWidth|align|right|next|after|extend|for|blur|drop|fn|setTimeout|s|span|paste|100|html|toLowerCase|width|keyup|jQuery|character'.split('|'), 0, {}))


Friday, 25 October 2013

loading image on button click in asp.net using c#,javascript

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        function ShowProgress() {
            setTimeout(function () {
                var modal = $('<div />');
                modal.addClass("modal");
                $('body').append(modal);
                var loading = $(".loading");
                loading.show();
                var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
                var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
                loading.css({ top: top, left: left });
            }, 200);
        }
        $('form').live("submit", function () {
            ShowProgress();
        });
        
</script>

    .modal
    {
        position: fixed;
        top: 0;
        left: 0;
        background-color: black;
        z-index: 99;
        opacity: 0.8;
        filter: alpha(opacity=80);
        -moz-opacity: 0.8;
        min-height: 100%;
        width: 100%;
    }
    .loading
    {
        font-family: Arial;
        font-size: 10pt;
        border: 5px solid #67CFF5;
        width: 200px;
        height: 100px;
        display: none;
        position: fixed;
        background-color: White;
        z-index: 999;
    }
</style>



<asp:Button ID="btn1" runat="server" Text="sample" onclick="btn1_Click" />
    <div style='width:680px; height:332px;  margin-left:80px; overflow:auto; margin-top:5px;'>
       <dx:ASPxGridView ID="ASPxGridView1" runat="server" Width="627px">
         </dx:ASPxGridView>
            <asp:Button ID="btnsample" runat="server" Text="Load Grid"
            onclick="btnsample_Click" />
           </div>
           </div>
           <div>
    <%-- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>--%>

             <div class="loading" align="center">
    Loading. Please wait.<br />
    <br />
    <img src="Images/preload.gif" alt="" />
</div>

load the data in button click event


and also we can do this same as in dropdown selection also for dropdown call the javascript function on dropdown onchange event

Loading gif Image on i frame loading

<script type="text/javascript">
        function hideLoading() {
            document.getElementById('divLoading').style.display = "none";
            document.getElementById('divFrameHolder').style.display = "block";
        }
    </script>

 <div id="divLoading">

        <asp:Image ID="imgloading" runat="server" ImageUrl="Images/preload.gif" />
    </div>
    <div id="divFrameHolder" style="display:none">
        <iframe src="LoadData.aspx" onload="hideLoading()" frameborder="1" scrolling="auto" width="650px;" height="500px">
     
        </iframe>
    </div>

Tuesday, 22 October 2013

Super Script to a radio button text(Trade Mark)


There is a ready TM character in unicode character set which should be already in superscript, it is0x2122. You can also write the TM character directly into the C# code or designer properties (you get the character by copying it from character map, or pressing Alt and  0153 from numpad). The character is available at least in font Microsoft Sans Serif (which should be a default for radio button).


radioButton1.Text = "MyProduct™";
radioButton2.Text = "MyProduct2" + (char)0x2122;

Thursday, 26 September 2013

Write and read text to/from a text file in asp.net

 string path = Server.MapPath("~/");
            TextWriter tw = new StreamWriter(path+"Textsample.txt",true);
            // write a line of text to the file
            tw.WriteLine(txtresult.Text);

            // close the stream
            tw.Close();
       txtfieldname.Text = "";
       txtvalue.Text = "";
       txtresult.Text = "";
       StreamReader tr = new StreamReader(path + "Textsample.txt");
       //TextReader tr = new TextReader(path + "Textsample.txt");
       // read a line of text
       //Console.WriteLine(tr.ReadLine());
       var lineCount = File.ReadAllLines(path + "Textsample.txt").Length;
       //Response.Write(lineCount);
       for (int i = 0; i < lineCount; i++)
       {
           txtresult.Text += tr.ReadLine();
       }
       // close the stream
       tr.Close();

Thursday, 12 September 2013

multiple deletes using checkbox in asp.net

 string strID = string.Empty;

        for (int i = 0; i < gvproviders.Rows.Count; i++)
        {
            CheckBox chkDelete = (CheckBox)gvproviders.Rows[i].
                             Cells[0].FindControl("chkname");
            if (chkDelete != null)
            {
                if (chkDelete.Checked)
                {

                    Label lbldeleteid = (Label)gvproviders.Rows[i].Cells[1].FindControl("controlid");
                    if (strID != string.Empty)
                        strID += ",";
                    strID += "" + lbldeleteid.Text + "";
                    //strID  = lbldeleteid.Text;
                    //idCollection.Add(strID);
                }
            }
        }
        string s1 = "delete from tblname where PId in(" + strID + ")";
       
        con.db1.Open();
        OleDbCommand cmd = new OleDbCommand(s1, con.db1);
       
        int j = Convert.ToInt32(cmd.ExecuteNonQuery());
        con.db1.Close();

remove a session variable in asp.net

Session.Remove("sessionvariablename");

save image in a folder in asp.net and validate image

Bitmap image1;
           
            image1 = new Bitmap(fupload1.PostedFile.InputStream);

            int x = image1.Width;
            int y = image1.Height;

            string[] exe = new string[3] {".jpg",".png",".gif" };


           
            if (i < 2000)
            {
                for (int k = 0; k < exe.Length;k++)
                {
                    if (lblextension.Text == exe[k])
                    {
                        if (x <= 1024 && y <= 768)
                        {
                            filename = Path.GetFileName(fupload1.PostedFile.FileName);
                             fname=j + extension;
                            fupload1.SaveAs(Server.MapPath("Files/" +fname ));
                            break;
                        }
                    }
                 
                }
            }

Find utl path in asp.net c#

Request.Url.GetLeftPart(UriPartial.Authority) +
     VirtualPathUtility.ToAbsolute("~/");