Saturday, 14 December 2013

Microsoft Bug - WebPage Keep on Rendering in IE but result in launching in Google Chrome

In this article we are going to see some of the different behavior that i have faced while working in ASP.NET, so i am going to share my experience based on ISSUE.

click here to see the details for bug
IE keep on Rendering the webpage

A webpage is keep on  rendering on the IE but not results in the view of the page, even if i launch the webpage in new session it result the same , but if i given the link in Google Chrome it result in Rendering the Webpage soon.

How a browser rendering the webpage is differs, Whether IE follows the visual studio code logic or based on Web standarad Rendering ? because why i have this doubt is the link is rendering correctly other browsers. How the webpage is rendering in the Google Chrome correctly with out keep on rendering .





In this article , i thought to share some problem i have faced in IE. i think it is understandable by everyone. 

Microsoft Bug - In Threading Value pass to each thread is sharing correct value is not receive on thread calling method

Hi In this article we are going to see some critical stuff in Microsoft Dot net Framework, few months back while i am testing a application. I framed a scenario in working , in that scenario i first uses the for each loop to do the work then i thought to change to for loop in C# 5.0 , The funniest thing is when you see logically both the loop are code in the same manner but the result in behavior is different and seems like Bug. so i tried in C# 4.0 version both the For each and For loop are not working in the same scenario. When i say about this to Microsoft they said like the C# compiler is designed like that from the beginning itself. they gave the work around like declare the temp variable to avoid the issue and work in expected manner. but the programmer will always concentrate on the logical thing not the work around things. The Programmer doesn't need to handle the life cycle of thread variable it should be handled by C# compiler Engine.Now let we see the Bug in detailed. 

If the C# 5.0 have a functionality of For each to work correctly then it should work same as For loop, because both are not working in C# 4.0 . so loop must work same for For and ForEach

Click the Link for Bug report details
In Threading Value pass to each thread is sharing

In Threading Value pass to each thread is sharing between the threads so correct value is not receive on thread calling method 


What is happening is we see in this in Example

static Semaphore sem = new Semaphore(3, 3);

                 static void Main(string[] args)
                 {

                         for (int i = 0; i < 11; i++)
                         {
                                 Thread sp= new Thread(() => RunTest(i));
                                 sp.Start();
                         }
                 }

         [MethodImpl(MethodImplOptions.Synchronized)]
         static void RunTest(int f)
                 {
                         try
                         {
                                 Console.WriteLine(f.ToString());
                                 sem.WaitOne();
                                 Console.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId);
                                 if (f % 2 == 0)
                                 {
                                            Console.WriteLine("7 sec");
                                            Thread.Sleep(7000);
                                 }
                                 else
                                 {
                                            Console.WriteLine(" 14 sec");                                                                 Thread.Sleep(14000);
                                 }
                         }
                         finally
                         {
                                 sem.Release();
                         }
                 }




Now in the above sample i am calling a Method from the thread but the method have a input parameter which is supplied from the for loop so now when a for loop executes each and every time input parameter changes , but when you print value in the called method value is repeating 


Expected output :
0,1,2,3,4,5,6,7,8,9,10

Actual Output:
0,1,2,2,2,5,6,6,6,8,10

So how to avoid this problem from Microsoft side there are saying that this C# compiler is designed like that so developers has to declare a temp variable to hold the value like below sample to avoid the error.


static Semaphore sem = new Semaphore(3, 3);

                 static void Main(string[] args)
                 {

                         for (int i = 0; i < 11; i++)
                         {
                                 int x=i; // New statement declared
                                 Thread sp= new Thread(() => RunTest(x));
                                 sp.Start();
                         }
                 }

         [MethodImpl(MethodImplOptions.Synchronized)]
         static void RunTest(int f)
                 {
                         try
                         {
                                 Console.WriteLine(f.ToString());
                                 sem.WaitOne();
                                 Console.WriteLine("Thread " + Thread.CurrentThread.ManagedThreadId);
                                 if (f % 2 == 0)
                                 {
                                            Console.WriteLine("7 sec");
                                            Thread.Sleep(7000);
                                 }
                                 else
                                 {
                                            Console.WriteLine(" 14 sec");                                                                 Thread.Sleep(14000);
                                 }
                         }
                         finally
                         {
                                 sem.Release();
                         }
                 }

Now in this one question if the C# compiler is behave like this , developers has to kept in mind that they have  to declare the temp variable while code the thread , that is not a rule specified in any OOPS concepts even there is no problem like this in Java Thread sharing a variable. But Microsoft changes the Foreach behavior in the C# 5.0 but have issue in C# 4.0 if they stated that is not a issue then why they change the Behavior of foreach in newer version below sample have issue in C# 4.0 but works  correctly in C# 5.0

In Foreach Loop

 void call(string[] args)
        {
            var runningnumbers = Enumerable.Range(1, 10);
            List<Action> procaction = new List<Action>();
            foreach (var item in runningnumbers)
            {
                Action lambda = () =>
                {
                    var result = 2 +10 + item;
                    Console.WriteLine(result);
                };
                procaction.Add(lambda);
            }

            foreach (var work in procaction)
            {
                work();
            }
            Console.Read();
        }




Solution

Expected output :
13
14
15
16
17
18
19
20
21
22

Actual Output:
22
22
22
22
22
22
22
22
22
22

but this problem is solved in C# 5.0 in ForEach loop,


From this article you can learn some of the basic things in C# and how to get the required output while developing from the global oops concepts.


Friday, 13 December 2013

JQuery Bug in Attr() function replace with Prop() function

This article reveals about the some Jquery function usage and the bug present in it, and how to resolve the bug and get the solution what we need ?


I have decide to do a some Test in Jquery by a sample having a TextArea and a checkbox. when i scroll the textbox from the top  to the bottom , checkbox should be enabled and checked, It the user scrolls upwards then automatically checkbox should be disabled and unchecked. To do this we are code it in Scroll function of text area like below


HTML:


<html>
<head>

    <title></title>
    <link  rel="Stylesheet" href="StyleSheet1.css" />
    <script type="text/javascript" src="jquery-1.9.1.intellisense.js">
    </script>
    <script type="text/javascript" src="jquery-1.9.1.js">
   </script>   
   <script type="text/javascript" src="jquery-1.9.1.min.js">
    </script>


<script type="text/javascript" >

    $(document).ready(function () {

        $('#agree').attr('disabled', true);
        $('#agree').attr('checked', false);


        var scrollheight = $('#area')[0].scrollHeight;
        var innerheight = $('#area').innerHeight();

        $('#area').scroll(function () {


            var scrollposi = $(this).scrollTop();

            var remaim = scrollheight - innerheight;
            $('#feed').text(Math.ceil(remaim));
            // alert(scrollposi);
            if (remaim <= scrollposi) {

                $('#agree').attr('disabled', false);
            }
            else {

                $('#agree').attr('disabled', true);
            }

        });


    });
</script>


</head>
<body align="center">
<div id="feed">dd</div>
<textarea id="area" cols="50" rows="30">
<!-- <textarea id="terms" rows="20" cols="50"> -->
<p>YouTube was founded by Chad Hurley, Steve Chen, and Jawed Karim, who were all early employees of PayPal.[7] Hurley had studied design at Indiana University of Pennsylvania, and Chen and Karim studied computer science together at the University of Illinois at Urbana-Champaign.[8]
According to a story that has often been repeated in the media, Hurley and Chen developed the idea for YouTube during the early months of 2005, after they had experienced difficulty sharing videos that had been shot at a dinner party at Chen's apartment in San Francisco. Karim did not attend the party and denied that it had occurred, but Chen commented that the idea that YouTube was founded after a dinner party "was probably very strengthened by marketing ideas around creating a story that was very digestible".[9]
Karim said that the inspiration for YouTube came from Janet Jackson's role in the 2004 Super Bowl incident, when her breast was exposed during her performance, and from the 2004 Indian Ocean tsunami. Karim could not easily find video clips of either event online, which led to the idea of a video sharing site.[10] Hurley and Chen said that the original idea for YouTube was a video version of an online dating service, and had been influenced by the website Hot or Not.[11][12]
</p>
</textarea>
<p><input type="checkbox" id="agree"  /> : Agree</p>
</body>
</html>




Now the Bug is when you scroll down and reaches the last position of scroll checkbox is checked and when you move up the checkbox is disabled and unchecked . But when you scroll again second time to the last position of scroll the checkbox is not enabled. Because attr function is not working in JQuery version above 1.9 but working in below version it can be resolve by replace with prop functiopn


       $('#area').scroll(function () {


            var scrollposi = $(this).scrollTop();

            var remaim = scrollheight - innerheight;
            $('#feed').text(Math.ceil(remaim));
            // alert(scrollposi);
            if (remaim <= scrollposi) {

                   $('#agree').prop('checked'true);
            }
            else {

                  $('#agree').prop('checked'false);
            }

        });


              

Change in the function attr to prop makes the functionality to work correctly.This bug may be fixed in the future versions


I hope this article will make you to aware of using correct functions in JQuery.


Read a Excelsheet from the fileupload in ASP.Net

In this article we are going to see how to read the Excel Sheet data while uploading from the File Upload control in ASP.Net. when user upload the Excel sheet we are going to read the data from the excel sheet and show in gridview.


Html :

<body>
    <form id="form1" runat="server">
    <fieldset style="width:700px;">
    <legend>Application Register</legend>
    <div>
    File Name :
    <asp:FileUpload runat="server" id="fileupload" />
    <br />
    <br />
    <br />
   
    <asp:Button  ID="upload"  runat="server" Text="Upload" onclick="upload_Click"
            style="height: 26px;position:relative;left:80px"/>
    <br />
    <br />
    <br />
    Data's :
    <asp:GridView ID="content"  runat="server">
    </asp:GridView>
    </div>
    </fieldset>
    </form>
</body>



C#:

  public partial class ReadExcel : System.Web.UI.Page
    {

        System.Data.OleDb.OleDbConnection oleconnection;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void upload_Click(object sender, EventArgs e)
        {
            string filepath = Server.MapPath("\\"+fileupload.FileName);

            fileupload.SaveAs(filepath);

            if (Path.GetExtension(filepath) == ".xls")
            {
                oleconnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"");
            }
            else if (Path.GetExtension(filepath) == ".xlsx")
            {
                oleconnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"");
            }

           
            OleDbCommand olecommand = new OleDbCommand("SELECT Serial,Name FROM [Sheet1$]",oleconnection);
            OleDbDataAdapter oleadapter = new OleDbDataAdapter(olecommand);
            DataSet ds = new DataSet();
            oleadapter.Fill(ds);

            content.DataSource = ds;
            content.DataBind();


        }
    }



Output:





I hope this article will help you to upload the excel file and the same time bind the data from the excel to Gridview.

Thursday, 12 December 2013

FTP - 421 , Clear text sessions are not accepted on this server [Resolved]

      Hi Guys , In this article we are going to see some ftp issue and the resolution for that. you will faced this issue once a time while working in the FTP. While connecting a FTP Server from you will see a Error message like

421 - Clear text session are not accepted on this server

How to solve this issue Let we see now ?
 Just add ftpes in front of your domain server thats it ex: "ftpes://ftp.domain.com" This will resolve the issue



ftpes://ftp.domain.com

In Old Server : 
server : ftp.domain.com
username : user
password : xxxx

In New Server:

server : ftpes://ftp.domain.com
username : user
password : xxxx

Please check that TLS Encryption support is set to Optional in FTP Service Configuration.I Hope this article will help some of them to do there work in quick manner.

Tuesday, 10 December 2013

JQuery Basics - Part 2

From this article we can see the usage and how to use the JQuery functions , samples and there usages.

$  : Is for the notation of Jquery.

.   : Is used for the notation of Class

#  : Is used for the notation of Id

document : specifies the HTML document

window: specifies the browser window.

ready() : Ready is used to execute the code only after the html document is loaded and ready.

$(document).ready(function(){
           });



focus() :   Focus is a event fire when the user focus on the particular element .

       $(document).ready(function () {

           $('#ka').focus(function () {
               $('#div').html('element focused');
           });

       });




focusin() : Focus in is a event fires when user focus in the specified element.

       $(document).ready(function () {

           $('#ka').focusin(function () {
               $('#div').html('element focused in');
           });

       });



focusout() : Focus out is a event fires when user focus out or leave from the specified element.


       $(document).ready(function () {

           $('#ka').focusout(function () {
               $('#div').html('element focused out');
           });

       });



blur() : Is also like the Focus out, when the user remove his focus from the element tag.


       $(document).ready(function () {

           $('#ka').blur(function () {
               $('#div').html('element focused out');
           });

       });
  

Multiple Selector : we can create a Jquery code multiple selector rather than single one by specify the id or class name with ,spaces.


       $(document).ready(function () {

           $('#button, #paragraph').click(function () {
               $('#div').html('element clicked');
           });

       });




fadein() : It shows the specifies element in specified speed.

    $('#button, #paragraph').click(function () {
               $('#img').fadeIn(2000, 'swing', function () {
                   $('#div').html(' fade in completed');
               });
           });

       });
  

fadeout() : it invisible the specified element in the specified speed

    $('#button, #paragraph').click(function () {
               $('#img').fadeOut(2000, 'swing', function () {
                   $('#div').html(' fade in completed');
               });
           });

       });



attr() : It is used to get the value of a attribute of html element or set the value for the attribute.

       $(document).ready(function () {

           var div = $('#div').attr('hovertext');

       });


<div id="div" hovertext="this is sample"></div>



val(): Gets the value of the html element.

$(document).ready(function () {

           var textval = $('#txt').val();
           alert(textval);

       });




length(): Get the length of the specified element

var textval = $('#txt').text().length;



* : indicates get the all elements
[ ] : specifies the conditional symbol
find(): Is used to find the element inside a specified element.

  $('input[type="text"]').find('*').last().addClass('bold').click(function () {
               $(this).prevAll().toggle();
           }).prevAll().hide(); ;

   
even, odd : Selection

$('table tr:even').css('background-color', 'yellow');
$('table tr:odd').css('background-color''yellow');




load() : Event fires when the specified element is loaded

           $(window).load(function () {
               alert('window loaded');
           });




unload() :  Event fires when the specified element is unloaded

           $(window).unload(function () {
               alert('window unloaded');
           });




contains() :  specifies whether the given string or data have the value specified

  $('#search').keyup(function () {

               var searchname = $(this).val();
               $('#names li').removeClass('high');

               if (jQuery.trim(searchname) != '')
                   $('#names li:contains("' + searchname + '")').addClass('high');

           });




change() : Event fires when the specified element undergoes and change in the attributes.

   $('#list').change(function () {
               var listvalue = $(this).val();
               $('#text_feed').html(' <a> you have selected ' + listvalue + '</a>');
           });




next() : This function will give the element next to the specified one.

    $('input[type="file"]').change(function () {
               $(this).next().attr('disabled', false);
           }).next().attr('disabled', true);



removeattribute() : This is used to remove the attribute from the element tag.

$('#names').removeAttr('hovertext');




click() : This event fires when user click on the specified element.

           $('#names').click(function () {
           });

  
dblclick() : This event fires when user double click on the specified element.

           $('#names').dblclick(function () {
           });



keyup() : This event fires when the user releases the key in the keyboard

$('#search').keyup(function () {

               var searchname = $(this).val();
               $('#names li').removeClass('high');

               if (jQuery.trim(searchname) != '')
                   $('#names li:contains("' + searchname + '")').addClass('high');

           });




keydown() : This event fires when the users press the key in the keyboard.

$('#search').keydown(function () {

               var searchname = $(this).val();
               $('#names li').removeClass('high');

               if (jQuery.trim(searchname) != '')
                   $('#names li:contains("' + searchname + '")').addClass('high');

           });




toggle() : This function is used to write the two function actions for a single event. So it will acts as one in first click and acts as another one in the second click

           $('#btnsh').click(function () {
               $('#Data').toggle();
           });
   

hover() : This event fires when user brings the mouse hover the specified element.


           $('button').hover(function () {
               alert('mouse hovered');
           });



scroll() : This event fires when the user scroll the specified element.

$('#textareas').scroll(function () {

               $('#Data').html($(this).scrollTop());

           });




mouseenter : This event fires when the mouse enter on the specified element.

     $('.hover').mouseenter(function (e) {

               var desc = $(this).attr('hovertext');

               $('#feedback').html(desc).show();
               $('#feedback').css('left', e.clientX + 20).css('top', e.clientY + 10);


           });


mouseleave : This event fires when the mouse leave from the specified element.

          $('.hover').mouseleave(function () {
               $('#feedback').hide();
           });




bind() : It is used to bind the same action for one or more events

     $('p').bind('mouseenter mouseleave', function () {
               $(this).toggleClass('bold');
           });




after() : It is used to find the element present after the given one.


   $('body').on('click', '.duplicate', function () 
       $(this).after('<input type="button" class="duplicate" value="submit" />');

           });




live() or on() : It  is used to add the element in the document with all event s and class bindings live to the running document.


$('body').on('change', '.file', function () {
               $(this).after('<input type="file" class="file" />');
           });




From this article i hope you can understand some of the basics functions and there usages with some sampels codes,We can see some more stuffs in Jquery in Next article.