using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
{ 
    protected void Page_Load(object sender, EventArgs e)
    {
        //BindData();
        //HideUnhide(true);     
    }

    protected void BindData()
    {
        gvStuff.DataSourceID = "odsStuff";
        gvStuff.DataBind();
    }
    protected void HideUnhide(bool s)
    {
        pnlContainer.Visible = s;
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        ClientScriptManager cm = Page.ClientScript;
        String cbReference = cm.GetCallbackEventReference(this, "'bindgrid'",
            "GetGVData", "'asyncgrid'", false);
        String callbackScript = "function CallServer(arg, context) {" +
            cbReference + "; }";
        cm.RegisterClientScriptBlock(this.GetType(),
            "CallServer", callbackScript, true);
    }

    #region ICallbackEventHandler Members
    private string _Callback;
    public string GetCallbackResult() {
        return _Callback;
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        try
        {
            BindData();           
            HideUnhide(true);           
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
                pnlContainer.RenderControl(new HtmlTextWriter(sw));
                _Callback = sw.ToString();
            }
        }
        catch (Exception ex){           
            throw ex;
        }
    }
    #endregion
    
}
