Tuesday 16 October 2012

Instead of default button click on page load, we can call any other particular button click

Instead of default button click on page load, we can call any other particular button click

In design page:

<script language="javascript" type="text/javascript"> 
 
        function clickButton(e, buttonid){  
 
          var evt = e ? e : window.event; 
 
          var bt = document.getElementById(
buttonid); 
 
          if (bt){  
 
              if (evt.keyCode == 13){  
 
                    bt.click();  
 
                    return false;  
 
              }  
 
          }  
 
        } 
 
    </script>


in Code behind:
    

    if (!IsPostBack)
         {
           
                 Textsearch.Attributes.Add("onkeypress", "return clickButton(event,'" + Btnsearch.ClientID + "')"); 
          
         }


Here after any keypress in the text seach box it will take to the search button click instead of default button
 
--------------------------------------------------------------------------
or
 
In form tag only we can set the Default focus and default button for a form as below
 
   <form id="form1" runat="server" defaultfocus="Textsearch" defaultbutton="Btnsearch">
 
 It will take given controls on page load...