welcome Netizen

welcome Netizen
Hi folks this site Share Basic Knowledge in .NET, DotNet, C#,DOT NET CODE, ASP.NET, VB.NET, DOT NET TRICKS,Dotnetcode,Android and Latest Technology Articles in VB,Android and ASP.NET

Monday, February 25, 2013

How to call server side method code using javascript in

Here I would like to share code and process to call server side from the javascript. But in many cases we need to call any event method from javascript,In such cases I hope this article would help to resolve your process.
Initially you can call server side method event by two method of code. Here I illustrate with proper example to when we need to call method event using javascript.
Scenario 1;
Take as scenario in textbox when user enter text after the completion when users press enter key, you need to call the method in server side.

<asp:TextBox ID="TextBox1"  runat="server" onkeypress="return EnterEvent(event)"></asp:TextBox>   
<asp:Button ID="Button3" runat="server" style="display:none" Text="Button" />

In javascript we need to write a function enter event to call server side code button event.
<script type="text/javascript">
function EnterEvent(e) {
        if (e.keyCode == 13) {
            __doPostBack('<%=Button3.ClientID%>', "");

So when user press enter key it will call the button3 server side code event.

Scenario 2:

Also we can call server side code by another using this anther way i.e.
function caller(){
        document.getElementById('<%= Button3.ClientID %>').click(); 

By using above code have alternate way to call server side from javascript.
I hope this article would helpful to you post your comments
Share this article with your friends by using share button.


Post a Comment