Monday, May 23, 2011

How to enable/disable control using javascript in

 <script type="text/javascript">
    function Disable()
           // Disable server side button with following syntax
           document.getElementById("button1").disabled = true;
 </script >


Monday, May 16, 2011

how to forcefully postback from javascript in ASP.Net

I am taking a simple example and telling you the way how to achieve this.
    I want to postback my page when user presses "Enter" key while focus is in textbox. Write the following code in this way.
on page load write the following code:
txtbox1.Attributes.Add("onKeyPress", "KeyPressTextBox()");

User can check that value passed from cleint side in his page like this and he/she can ignore any other calls on this argument value

protected void Page_Load(object sender, EventArgs e)
if(HttpContext.Current.Request.Params["__EVENTARGUMENT"] == "argument")
            // Enter you code


 <script type="text/javascript">
  function KeyPressTextBox() {
  //var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (event.keyCode == 13) {
       event.returnValue = false;
       event.cancelBubble = true;
      __doPostBack('<%=UpdatePanel1.ClientID %>', "argument");

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
             <asp:TextBox ID="txtbox1" runat="server" Width="160px"></asp:TextBox>

Thursday, May 12, 2011

Removing double backslashes in C#

It adds the backslashes to indicate quotes in the middle of the string. The backslashes aren't actually there, the quotes are.
Remove the quotes like that:
myTestString.Replace("\"", string.Empty);