.Click event handler is not getting called after a Click ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cyclestump

    .Click event handler is not getting called after a Click ?

    We're using .NET 2.0, VB. I expect a .Click event handler to be called, but it's not.

    When I click on the webpage link named btnSearch, the confirmSearchOK () javascipt function is called(I see this when I uncomment the alert() ), which contains the __doPostBack() call. On the .VB side, the handler never gets called. BTW, the handler was created by double-clicking on the .ASPX object in the 'Design' mode.

    Any help would be appreciated.
    Thanks

    Javascipt:
    Code:
    function confirmSearchOK() {
    		var planSel = document.getElementById("<%= ddlPlanID.ClientID %>").selectedIndex;
    		var opSel = document.getElementById("<%= ddlOfferingPeriod.ClientID %>").selectedIndex;
    		var useEASi = document.getElementById("<%= hUseEASi.ClientID %>").value;
    		var epError = 0		
    		
            if( useEASi == 'Y'){
                if (document.getElementById("<%= ddlEnrollmentPeriod.ClientID %>").selectedIndex == 0)
                    epError = 1;        
    }
            
    //alert("planSel: "+planSel+", opSel: "+opSel+", useEASi: "+useEASi+", epError: "+epError );
    
            if( planSel == 0 )
    		    alert("Error, must choose a Plan prior to Search");
            else if( opSel == 0 )
    		    alert("Error, must choose an Offering Period prior to Search");
    		else if( epError == 1 )
    		    alert("Error, must choose an Enrollment Period prior to Search");
            else                
    	        __doPostBack('btnSearch','');	        
    }
    asp.net
    Code:
    <td align="left" class="FormFieldCell" colspan="3" style="white-space: nowrap">
       <EASI:LinkButton ID="btnSearch" runat="server" CausesValidation="False" ClientScript="confirmSearchOK();"                  UseSecurityLevel="True">Search</EASI:LinkButton></td>

    VB.NET event handler

    Code:
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
     
      'handle the event here
    
    End Sub
    Last edited by Frinavale; Oct 14 '10, 03:27 PM. Reason: Separated different code types into their own code sections so that it is easier to see and understand.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What is an "EASI" LinkButton?
    Why don't you just use an ASP.NET LinkButton?

    Try modifying your JavaScript method so that it returns "true" if you want the postback to occur...and "false" if you want it to stop.

    Then change the LinkButton to so that it "returns" the value that is returned by the JavaScript method... This should stop the postback from occurring (but then again I've nevers een an EASI LinkButton before.......)
    Code:
    <EASI:LinkButton ID="btnSearch" runat="server" CausesValidation="False" ClientScript="return confirmSearchOK();" UseSecurityLevel="True">Search</EASI:LinkButton>
    JavaScript modification suggestion:
    Code:
    function confirmSearchOK() {
            var planSel = document.getElementById("<%= ddlPlanID.ClientID %>").selectedIndex;
            var opSel = document.getElementById("<%= ddlOfferingPeriod.ClientID %>").selectedIndex;
            var useEASi = document.getElementById("<%= hUseEASi.ClientID %>").value;
            var epError = 0        
     
            if( useEASi == 'Y'){
                if (document.getElementById("<%= ddlEnrollmentPeriod.ClientID %>").selectedIndex == 0)
                    epError = 1;        
    }
     
    //alert("planSel: "+planSel+", opSel: "+opSel+", useEASi: "+useEASi+", epError: "+epError );
     
            if( planSel == 0 )
            {    alert("Error, must choose a Plan prior to Search");
                 return false;
            }
            else if( opSel == 0 )
            {    alert("Error, must choose an Offering Period prior to Search");
                  return false;
            }
            else if( epError == 1 )
            {    alert("Error, must choose an Enrollment Period prior to Search");
                 return false;
            }
    //        else                
    //            __doPostBack('btnSearch','');            
            return true;
    }
    -Frinny

    Comment

    Working...