Thursday, September 20, 2012

How to quickly disable an asp.net button from client side



usually we will create a JavaScript function to handle the client side click event.

something like the following

In Client Side

 function disableButton(buttnId) {
            document.getElementsByName(buttnId)[0].disabled = true;
 }


In Server Side
   
buttonControl.Attributes.Add("onclick", "this.disabled=true;");


In Design Mode
However we can do it very quick in the design mode, set its disabled attribute to be true at
onClientClick event.

OnClientClick="this.disabled=true;"


<asp:Button runat="server" ID="btnSubmit" Text="Submit Data" 
OnClick="btnSubmit_Click" Enabled="false" OnClientClick="this.disabled=true;" /> 
 
I had found one serious issue during this implementation. 
though i can disable the button to prevent the user double click on it.
However the server side event had been disabled as well. i believe when i disabled
the button in the client side. when page was not pushed back to the server. 
then it will not execute the server side click event and force the page to refresh.
 
we must manually refresh the page on the client side. 
the line of code will hook up the _doPostBack() event on the button control.
btnSubmit.Page.ClientScript.GetPostBackEventReference(btnSubmit,"") 

  protected void Page_Load(object sender, EventArgs e)
  {
     if (!IsPostBack)
     {
         btnSubmit.Attributes.Add("onclick""javascript:" +btnSubmit.ClientID +".disabled=true;" 
             +btnSubmit.Page.ClientScript.GetPostBackEventReference(btnSubmit,""));
     }
 }
 
when you click on the button, the exception will thrown immediately
the Error Message is "Microsoft JScript runtime error: The value of the property '__doPostBack' 
is null or undefined, not a Function object"
you will find the solution from this link. Ensure that __doPostBack() function is implemented on the page  

 

Thursday, September 6, 2012

First Sharepoint-Host app development in Sharepoint 2013 Beta

Finally i completed my very first app development in SharePoint 2013


when you start your first try, a few step follow in order to make your first development smooth.

First you must create a separate domain that different from your current Sharepoint

in my case, i have SP2013.Local to host my Sharepont 2013.

and I create a separate domain called sp2013app.com to host all the Sharepoint Host App.

please note that it also work if you create a sub-domain under SP2013.Local. I test it with a sub-domain apps.SP2013.Local

the following link will give you  a very informative instruction to create the domain for your SharePoint Host App. it covered both the sub-domain case and a brand new domain case as well.

Setting up your App domain for SharePoint 2013






after you deploy the your app to SharePoint 2013 Developer Site which is ran under Developer site template. you must add a new key under the Lsa property. the new key will prevent the constant popup to ask for the credential.