Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I have created a crystal report and attached to a button on aspx page. But code behind the button is not called at all. Please help.

axpx page Code:

ASP.NET
<%@ Page Title="Department Average Competency Rating" Language="vb" AutoEventWireup="false" MasterPageFile="~/PageTemplate.master"
    CodeBehind="DepartmentAverageRating.aspx.vb" Inherits="PerformanceAppraisal.DepartmentAverageRating" %>

<%@ Register Src="Controls/EmployeeHeader.ascx" TagName="EmployeeHeader" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
. .. .. .. .. .. .. .. .. .. .. .. .. .. .
. .. .. .. .. .. .. .. .. .. .. .. .. .. .
. .. .. .. .. .. .. .. .. .. .. .. .. .. .
  
        <tr id="ViewReport"  runat="server">
            <td colspan="2" align="center">
                <asp:Button ID="btnView" runat="server" CssClass="buttonStyle" Text="View Report" />
            </td>     
        
    </table>
    <br />
    <br />

************************************************************************************************

Code behind the page:
VB
Partial Public Class DepartmentAverageRating
    Inherits System.Web.UI.Page

    'Private _employee As Employee

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("AppraisalId") = -1
        If Not Page.IsPostBack Then
            'If (Security.UserRole <> UserRole.Manager Or Security.UserRole <> UserRole.Supervisor) AndAlso Not Utility.UserIsHr Then
            '    Response.Redirect("EmployeeSummary.aspx")
            'End If
            '_employee = New Employee(Security.CurrentEmployee)
            txtStartDate.Focus()
        End If
    End Sub

    Private Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click
        If Page.IsValid Then
            'Launch the report with the appropriate parameters.
            Dim strReportUrl As String

            strReportUrl = "ShowReport.ashx?Type=DepartmentAverageRating.rpt&StartDate=" & txtStartDate.Text & "&EndDate=" & txtEndDate.Text & "&Format=" & ddlReportFormat.SelectedValue

            ClientScript.RegisterClientScriptBlock(Me.GetType(), "OpenWin", _
                   "<script>window.open('" & strReportUrl & "')</script>", False)
        End If
    End Sub

End Class
Posted
Updated 23-Dec-13 7:17am
v4
Comments
creepz03 19-Dec-13 19:05pm    
Dude, that's a pretty long code.. And I dont think a lof of us here had the luxury of time to check it.. might as well remove the comments, get the css code in one line per declaration, etc.
thatraja 23-Dec-13 8:19am    
agree
creepz03 19-Dec-13 19:09pm    
Oh.. and just guessing, does the pageload fires after hitting the button? cause if it does then the problem could be on the page load and it might be interrupting the button event. Try putting a break point in this line of code "Session("AppraisalId") = -1" and then run through it.. tell me if there's an error.
Member 10477790 23-Dec-13 11:19am    
The page load event is firing after hitting the button but the button event is not firing. I have kept a break point on "Session("AppraisalId") = -1" and it hits the break [point but doesn't give any error. It's not going to the button click event. I am not sure what to do. Any help is appreciated.
JoCodes 23-Dec-13 11:22am    
Please dont dump your code like this. It will draw away even people who would like to help you

1 solution

Why AutoEventWireup="false" in the Page Directive?
It should be true in order to fire the Events.

Also define OnClick event for Button in aspx page.
ASP.NET
<asp:Button ID="btnView" runat="server" CssClass="buttonStyle" Text="View Report" OnClick="btnView_Click" />

Otherwise, the event will not get fired.
 
Share this answer
 
v2
Comments
Member 10477790 23-Dec-13 13:21pm    
I am getting this error after making the changes "'btnView_Click' is not a member of 'ASP.departmentaveragerating_aspx'." and when I set a break point in the click event code .. it shows warning message as "The breakpoint will not be hit . No executable code is associated with this line"
Do one thing. Delete this event completely from Code Behind.
Now go to aspx "Design View", you can see the Button. Double click on the Button.
It will create a Button Click event in Code Behind for you. Use that.
Member 10477790 24-Dec-13 10:24am    
I did that also..but it is still not firing but it is firing for other pages..not sure why it is not firing for this particular page..
Did you set AutoEventWireup="true"?
Member 10477790 24-Dec-13 12:57pm    
yes i did that too..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900