file extension validation in jQuery

Hello Friends,

Recently one of my project require file extension validation. I am using jquery to achive this. So, i have done it in simple way with jquery as follow

$(function ()
{
   $('#btnSubmit').click(function ()
   {
      var ext = ['jpeg', 'jpg', 'png', 'gif'];
      var file = $("file").val();
      if ($.inArray(file.split('.').pop().toLowerCase(), ext) == -1)
      {
          alert ('Only jpg, png and gif are allowed.');
      }
   }
}

Include HTML as follow.



It is work with jQuery js. So, include jQuery js file. Hope it will help someone!!!!

How to call server side button event from javascript function

Hello Friends,

Today I am going to describe how to call server side event from client side.

we can do this by different ways like web service and Page Methods, using jquery, using scriptmanger and __dopostback, using javascript etc.

Today I will show you how to call a server-side ASP.NET button event from client-side using JavaScript function.

See the below aspx code;


   
This is test page :

You can see that, I have defined one server side button with onclick event.

Here, I have also defined aspx label and client side button.

I have used client side button event for calling the server side button event; where I have write test message in aspx label.

see below code for aspx code behind button event


protected void btnTest_Click(object sender, EventArgs e)
{
    lblMessage.Text = "Test message";
}

Now how can we call this event from client side function; see the below client side funtion


function TestCall()
{
     var btnTest = document.getElementById("<%= btnTest.ClientID %>");
     btnTest.click();
}

That’s it.

Hope this will help you !!….