Thursday, September 29, 2011

how to start thread ?

using System;

using System.Threading;

public class ThreadTest {

    public void csharpeMethod() {

        int result = 1;

        Console.WriteLine(result.ToString() + "  Thread ID is  " +

                          AppDomain.GetCurrentThreadId().ToString());

    }

    public static void Main() {

        ThreadTest objThread = new ThreadTest ();

        objThread.csharpeMethod();

        ThreadStart objts = new ThreadStart(objThread.csharpeMethod);

        Thread obj = new Thread(objts);

        obj.Start();

    }

}


Sunday, September 25, 2011

Use Viewstate with UpdatePanel in asp.net

ViewState Can not use with UpdatePanel in ASP.NET Because When Page is not postBack at time viewstate is Available and If  Page is PostBack at time viewstate kill (Destroy). Now New ViewState is Generate that is used by On in Update Panel What is Solution fo viewstate? Solution is that make EnableViewState="true" in UpdatePanel. Put Hidden Filed in UpdatePanel and store Value in Hidden Field. Problem is Solve. Now If You want to use JavaScript Function Then you can Register That JavaScript Function in UpdatePanel Load Event
protected void UpdatePanel1_Load(object sender, EventArgs e)
{
   // Add client-side script to call the JavaScript  function
   ScriptManager.RegisterStartupScript(this, this.GetType(),
                  Guid.NewGuid().ToString(),
                  "YourJAVASCRIPTfunctionName();", true);
}   

Sunday, July 17, 2011

calling asp.net method from jquery

ASP.NET Code Behind Method is Call by jQuery Function and AJAX.
Let's See How
jQuery.ASPX 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jQuery.aspx.cs"
Inherits="jQuery" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"
type="text/javascript"></script>

      <script type ="text/javascript">

          $(document).ready(function () {

              $('#<%=btnjQuery.ClientID %>').click(function () {

                  $.ajax({

                      type: "POST",

                      url: "jQuery.aspx/CodeBehindMethod",

                      data: "{}",

                      contentType: "application/json; charset=utf-8",

                     dataType: "json",

                     async: true,

                     cache: false,

                     success: function (msg) {

                         $('#result').text(msg.d); 

                     }

                 })

                 return false;

             });

         });

     </script>
    
    
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="btnjQuery" runat="server" Text="call jQuery Function" />

    <br /><br />

    <div id="result"></div>
    </div>
    </form>
</body>
</html>
well do not forget System.Web.Services NameSpace and
Method Must be Static and it's Variable also Static.
jQUery.aspx.cs 
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;

public partial class jQuery: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]

    public static string CodeBehindMethod()

       {

           return "Message from code behind Method.";

       }
}