Friday, January 22, 2010

Know the control which caused the postback

8:28 PM Posted by Unknown , No comments
I got this from some site. It can be used to know the control which caused the postback.

 public static Control GetPostBackControl(Page thePage)
    {
        Control myControl = null;
        string ctrlName = thePage.Request.Params.Get("__EVENTTARGET");
        if (((ctrlName != null) & (ctrlName != string.Empty)))
        {
            myControl = thePage.FindControl(ctrlName);
        }
        else
        {
            foreach (string Item in thePage.Request.Form)
            {
                Control c = thePage.FindControl(Item);
                if (((c) is System.Web.UI.WebControls.Button))
                {
                    myControl = c;
                }
            }

        }
        return myControl;
    }

Display updateprogress in the clicked position

8:22 PM Posted by Unknown , No comments
On the following example, progress bar(UpdateProgress1) is displayed on the position of the button which got clicked


function pageLoad()

     {     

           var manager = Sys.WebForms.PageRequestManager.getInstance();
   
          
       manager.add_beginRequest(OnBeginRequest);
   
    }

    function OnBeginRequest(sender, args)
    {
 
          var postBackElement = args.get_postBackElement();
          var position = $("#"+postBackElement.id).offset();
         
         
          $("#<%=UpdateProgress1.ClientID%>").css({'position' : 'absolute', 'z-index' : '1002', 'overflow' : 'auto','top' : position.top,'left' : position.left}).fadeIn(100);

}

JQuery default functions

8:21 PM Posted by Unknown No comments
Following is the jquery default function that is run. we can use this to get the ajaxrequests
function pageLoad() {
            if (!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(AjaxBegin);      
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(AjaxEnd);      

            }
        }

8:16 PM Posted by Unknown No comments
Use ScriptManager.RegisterStartupScript, when using ajax updatepanel to add javascript from codebehind.
for eg. just showing a message box, on of a button in updatepanel
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "scriptname", "var position=$('#" + Btn.ClientID + "').offset();$('#').html('Button clicked').css(position).fadeIn(2000).fadeOut(2000);", true);

can get position using position method of jquery

First Post

8:14 PM Posted by Unknown No comments
My First Post. Hope this blog will help me and others too.

I am going to post all the new things I am learning everyday regarding programming. Hope it helps somebody.