Results 1 to 4 of 4

Thread: Handling onclick event issue

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Handling onclick event issue

    Hello Good folks,

    I am having a small problem and I have been trying to figure this out for the last 2 days...very frustrated.
    There is a server side button control <asp:Button/> on my .aspx page. There are two event handlers on this control. One is clientside (in Javascript) and server side. When the user clicks on the button only clientside script should be fired (not the server side).the user enters some input into a text box and clicks the button again. Now only the server side script should be executed. Client side script should not be executed.

    So far, everything works but for some reason after the server side script get executed again the clientside script gets executed. I have to no clue why this is happening...can someone advise me please

    Code:
    <%@ Page Title="" Language="C#" MasterPageFile="~/QRMDMS.Master" trace="false" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="FHLBSF.QRMDMS.WebUI.WebForm7" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    
    <script  type="text/javascript">
        function AddClientSide() {
    
            alert("started the client side script");
    
    
            var varLabelBSISTypes = document.getElementById("<%=LabelBSISType.ClientID%>");
            varLabelBSISTypes.style.display = "block";
            varLabelBSISTypes.style.visibility = "visible";
    
            var varTextBoxBSISType = document.getElementById("<%=TextBoxBSISType.ClientID%>");
            varTextBoxBSISType.style.display = "block";
            varTextBoxBSISType.style.visibility = "visible";
    
            var varButtonAdd = document.getElementById("<%=ButtonAdd.ClientID%>");
    
            var varproperty = varButtonAdd.getAttribute("value");
    
            if (varproperty == "Save") {
                alert("button now is in save mode");
    
                varButtonAdd.setAttribute("value", "Add");
                document.getElementById("<%=ButtonEdit.ClientID%>").disabled = false;
                document.getElementById("<%=ButtonRemove.ClientID%>").disabled = false;
                document.getElementById("<%=TextBoxBSISType.ClientID%>").disabled = true;
    
                return false;
            }
            else {
                alert("button now is in add mode");
                varButtonAdd.setAttribute("value", "Save");
                document.getElementById("<%=ButtonEdit.ClientID%>").disabled = true;
                document.getElementById("<%=ButtonRemove.ClientID%>").disabled = true;
                document.getElementById("<%=TextBoxBSISType.ClientID%>").disabled = false;
                return true;
            }
    
    
    
    
    
        }
    
    </script>
    
    <div style="height: 25px">
    
    </div>
    
    <div style="table-layout: fixed; width: 600px; height: 65px; position: fixed; z-index: auto;">
    
        <fieldset style="width: 382px; height: 47px;">
            <legend style="font-weight: bold">BS-IS Types</legend>
            <asp:DropDownList ID="DropDownListBSISTypes" AutoPostBack="false" runat="server" 
                Height="23px" Width="362px">
            
             </asp:DropDownList>
               
        </fieldset>
        
        <asp:Button ID="ButtonAdd" UseSubmitBehavior="true" OnClick="ButtonAddClick" OnClientClick="return !AddClientSide();" Text="Add" runat="server" /> 
        <asp:Button ID="ButtonEdit" runat="server" Text="Button" />
        <asp:Button ID="ButtonRemove" runat="server" Text="Remove" />
    
     <div>
            <asp:Label ID="LabelBSISType" runat="server" Text="BS-IS Type"></asp:Label>
            <asp:TextBox ID="TextBoxBSISType" runat="server" Width="282px"></asp:TextBox>
        </div>
    
      </asp:Content>

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Handling onclick event issue

    The only time the client side will execute and not the server side, is if the script returns a false value. Otherwise they will both always execute. I believe.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: Handling onclick event issue

    True.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Re: Handling onclick event issue

    any help on this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width