Using Microsoft.Reporting.WebForms.ServerReport in Click procedure prevents it from firing

I have an app developed in Visual Studio 2010 using VB.  It's a very simple app with two pages, a login page and a page that allows the user to enter notes and open a report that displays all notes for an item selected from a drop down list.  The notes page has a master page that provides a header, sidebar and footer. The user selects an item from the drop down list and if they click on a button from the footer a report should open.  This works on my development machine but not when deployed to the server.  The issue revolves around this line of VB code, "Dim r = New ServerReport".  I removed everything from the procedure except that line and some code to write a message in a text box.  If I comment out that line the message is written if I uncomment it, it does not.  There is another button in the footer that allows the user to submit a new note.  That button works on both the development machine and the production server.

My development machine is running Windows 7 Professional SP 1 and IIS.  The server is running Windows server 2012 R2 Standard and IIS.  Below is my code.

Site.Master:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Site Master Page</title>
    <asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder>
   
    <link href="~/Styles/Master.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <script src="<%=ResolveUrl("~/Scripts/jquery/jquery-1.4.1.js")%>" type="text/javascript"></script>
    <script src="<%=ResolveUrl("~/Scripts/jquery/jQueryUI.js")%>" type="text/javascript"></script>
    <script src="<%=ResolveUrl("~/Scripts/Dialog.js")%>" type="text/javascript"></script>
    <script src="<%=ResolveUrl("~/Scripts/Master.js")%>" type="text/javascript"></script>
    <script type="text/javascript">
        window.onbeforeunload = confirmExit;
    </script>
    
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
            <Services>
            </Services>
    </asp:ScriptManager>           
        <div id="divPageWrapper">
            <div id="divHeaderOne">
                <asp:Image runat="server" ID="HeaderImage" CssClass="HeaderOneImage" ImageUrl="~/Images/HeaderLogo.gif" AlternateText="Logo" />
            </div>
            <div id="divMenu" >
            </div>
            <div id="divHeaderTwo">
                <asp:Label ID="lblFormTitle" runat="server" Text="Notes"></asp:Label>
            </div>
            <div id="divHeaderThree">
                &nbsp;
            </div>
            <div id="divSideBar">
                <asp:LinkButton ID="LogOff" runat="server" onclick="LogOff_Click" CausesValidation="False">Log Off</asp:LinkButton><br /><br />
                <asp:UpdateProgress ID="UpdateProgressButton" runat="server">
                    <ProgressTemplate>
                        <div class="Progress"></div>
                        <br />
                        <div class="PleaseWait">Please Wait...<asp:ValidationSummary 
                                ID="ValidationSummary1" runat="server" HeaderText="Data Entry Error." 
                                ShowMessageBox="True" ShowSummary="False" Width="93px" />
                        </div>
                    </ProgressTemplate>
                </asp:UpdateProgress>
            </div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <div id="divMainContent">
                        <asp:ContentPlaceHolder ID="cp1" runat="server">
                            Under Construction
                        </asp:ContentPlaceHolder>
                    </div>
                    <div id="divFooter">
                        <asp:Panel ID="pnlButtons" runat="server" Visible="true">
                           <asp:Button ID="btnInsertUpdate" runat="server" Text="Submit" Visible="False" />
									<asp:Button ID="btnReport" runat="server" Text="Report" Visible="False" CausesValidation="False"/>
                        </asp:Panel>                       
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>

Open in new window


Site.Master.vb (the problem occurs in the last line of btnReport_Click:

Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
Imports System.IO

Public Class Site
	Inherits System.Web.UI.MasterPage
	Protected WithEvents LogOff As LinkButton

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	End Sub

	Protected Sub LogOff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LogOff.Click
		Session.Abandon()
		'Close the appliction window.
		Dim CloseScript As String
		CloseScript = "<script language=""javascript"">" & vbCrLf & "window.close(); window.onbeforeunload = null;</script>"
		Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "Close", CloseScript)
	End Sub

	Protected Sub btnInsertUpdate_Click(sender As Object, e As EventArgs) Handles btnInsertUpdate.Click
		Dim txtNote As TextBox = cp1.FindControl("txtNote")
		Dim ddlSubordinates As DropDownList = cp1.FindControl("ddlSubordinates")
		Dim CurrentUser As User = Session("CurrentUser")
		Dim gvNotes As GridView = cp1.FindControl("gvNotes")
		Dim txtMessage As TextBox = cp1.FindControl("txtMessage")
		txtMessage.Visible = False
		txtMessage.Text = ""

		Try
			If txtNote.Text.Length > 4000 Then
				txtMessage.Visible = True
				txtMessage.Text = "You have exceeded the maximium number of characters available for a note by aproximately " & txtNote.Text.Length - 4000 & " characters.  Please reduce the number of characters and submit again."
			Else
				Using context = New SupervisorsNotesEntities
					Dim Note = tabNote.CreatetabNote(0, ddlSubordinates.SelectedValue, CurrentUser.EmployeeNumber, txtNote.Text, DateTime.Now)
					context.tabNotes.AddObject(Note)
					context.SaveChanges()
					txtNote.Text = ""
					gvNotes.DataSource = context.GetNotesForGrid(ddlSubordinates.SelectedValue)
					gvNotes.DataBind()
				End Using
			End If
		Catch ex As Exception
			txtMessage.Visible = True
			txtMessage.Text = "The following error has occurred on the Notes page of the Supervisors Notes application, '" & ex.Message & "' Please open a ticket with the help desk.  Copy this message and paste into the message to the help desk.  Please be sure to include any other pertinent information such as exactly what you were doing when this error occurred."
		End Try
	End Sub


	Protected Sub btnReport_Click(sender As Object, e As EventArgs) Handles btnReport.Click
		Dim txtNote As TextBox = cp1.FindControl("txtNote")
		txtNote.Text = "This works"
		Dim r = New ServerReport
	End Sub
End Class

Open in new window


Notes.aspx

<%@ Page Title="Notes" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/Site.master" CodeBehind="Notes.aspx.vb" Inherits="SupervisorsNotes.Notes" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cp1" runat="server">
	<asp:TextBox ID="txtMessage" runat="server" style="margin-bottom: 0px" 
	ReadOnly="true" BackColor="#E1E1E1" ForeColor="red" Width="890px" 
	BorderStyle="None" TextMode="MultiLine" Visible="False" Height="64px"></asp:TextBox>
	<br />
	&nbsp<asp:Label ID="lblSubordinates" runat="server" Text="Subordinates:"></asp:Label>&nbsp<asp:DropDownList ID="ddlSubordinates" runat="server" AutoPostBack="True"></asp:DropDownList>&nbsp;<asp:Label 
	ID="lblAllStaff" runat="server" Text="All Staff With Notes:" Visible="False"></asp:Label>&nbsp;<asp:DropDownList 
	ID="ddlAllStaff" runat="server" Visible="False"></asp:DropDownList>
	<br />
	<br />

	<asp:Label ID="lblNote" runat="server" Text="Note:" Visible="False"></asp:Label>
	<asp:RequiredFieldValidator ID="reqNote" runat="server" ControlToValidate="txtNote" ErrorMessage="You must enter a note before submitting.">*</asp:RequiredFieldValidator>
	<asp:TextBox ID="txtNote" runat="server" Height="36px" Visible="False" Width="890px" TextMode="MultiLine" MaxLength="3800"></asp:TextBox>
	<asp:GridView ID="gvNotes" runat="server" CssClass="Grid" AutoGenerateColumns = "false">
	             <RowStyle CssClass="Row" />
                <AlternatingRowStyle CssClass="AlternateRow" />
                <Columns>
                    <asp:TemplateField HeaderText="Note Index" ItemStyle-Width="0px" Visible="false">
                        <ItemTemplate>
                            <asp:Label ID="lblNotesIndex" runat="server" Text='<%# Bind("NotesIndex") %>'></asp:Label>
                        </ItemTemplate>
                        <FooterTemplate>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Entered By" SortExpression="EnteredBy" ItemStyle-Width="190px">
                        <ItemTemplate>
                            <asp:Label ID="lblEnteredBy" runat="server" Text='<%# Bind("EnteredBy") %>'></asp:Label>
                        </ItemTemplate>
                        <FooterTemplate>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Note" SortExpression="Note" ItemStyle-Width="600px">
                        <ItemTemplate>
                            <asp:Label ID="lblNote" runat="server" Text='<%# Bind("Note") %>'></asp:Label>
                        </ItemTemplate>
                        <FooterTemplate>
                        </FooterTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Date Entered" SortExpression="DateEntered" ItemStyle-Width="90px" ItemStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <asp:Label ID="lblEnteredByEmpNumber" runat="server" Text='<%# Bind("DateEntered") %>'></asp:Label>
                        </ItemTemplate>
                        <FooterTemplate>
                        </FooterTemplate>
                    </asp:TemplateField>
                </Columns>
	</asp:GridView>
</asp:Content>

Open in new window


Notes.aspx.vb

Public Class Notes
	Inherits System.Web.UI.Page
	Private WithEvents btnInsertUpdate As Button
	Private WithEvents btnReport As Button

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		If Not IsPostBack Then
			PopulateLists()
			btnInsertUpdate = CType(Master.FindControl("btnInsertUpdate"), Button)
		End If
	End Sub

	Private Sub PopulateLists()
		Dim CurrentUser As User = Session("CurrentUser")
		Dim db As New UltiproDataEntities()
		Dim SubordinatesList As List(Of GetSubordinates_Result) = db.GetSubordinates(CurrentUser.EmployeeNumber).ToList()
		ddlSubordinates.DataSource = SubordinatesList
		ddlSubordinates.DataValueField = "EmployeeNumber"
		ddlSubordinates.DataTextField = "NameLastFirst"
		ddlSubordinates.DataBind()
		ddlSubordinates.Items.Insert(0, New ListItem("", "0"))
	End Sub

	Protected Sub ddlSubordinates_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlSubordinates.SelectedIndexChanged
		Try
			btnInsertUpdate = CType(Master.FindControl("btnInsertUpdate"), Button)
			btnReport = CType(Master.FindControl("btnReport"), Button)
			If ddlSubordinates.SelectedIndex <> 0 Then
				lblNote.Visible = True
				txtNote.Visible = True
				btnInsertUpdate.Visible = True
				btnReport.Visible = True
			Else
				lblNote.Visible = False
				txtNote.Visible = False
				btnInsertUpdate.Visible = False
				btnReport.Visible = False
			End If
			Dim context As New SupervisorsNotesEntities()
			gvNotes.DataSource = context.GetNotesForGrid(ddlSubordinates.SelectedValue)
			gvNotes.DataBind()
		Catch ex As Exception
			Response.Write(ex.Message)
		End Try
	End Sub

End Class

Open in new window

leskellyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leskellyAuthor Commented:
To see if the master page was part of the issue I tried adding a button to the child page with the same line of code but it didn't fire either.
Bob LearnedCommented:
I can't quite see what you are doing in all that code.  

What report are you trying to work with?
Is there any JavaScript in use here?
Are you using UpdatePanel?
leskellyAuthor Commented:
What I posted is a striped down version of my code.  At this point I'm not trying to open any report I just want to get the on click event for the button to fire.  Below is the on click function.

      Protected Sub btnReport_Click(sender As Object, e As EventArgs) Handles btnReport.Click
            Dim txtNote As TextBox = cp1.FindControl("txtNote")
            txtNote.Text = "This works"
            Dim r = New ServerReport
      End Sub

  The line that causes the problem is "Dim r = New ServerReport".  If I comment it out the function runs, when it is not commented out the function does not run.

ServerReport is defined in Microsoft.Reporting.WebForms.

The button is in an update panel as shown below:

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <div id="divMainContent">
                        <asp:ContentPlaceHolder ID="cp1" runat="server">
                            Under Construction
                        </asp:ContentPlaceHolder>
                    </div>
                    <div id="divFooter">
                        <asp:Panel ID="pnlButtons" runat="server" Visible="true">
                           <asp:Button ID="btnInsertUpdate" runat="server" Text="Submit" Visible="False" />
                                                      <asp:Button ID="btnReport" runat="server" Text="Report" Visible="False" CausesValidation="False"/>
                        </asp:Panel>                      
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Bob LearnedCommented:
Does the code work without the UpdatePanel?
leskellyAuthor Commented:
Nope, I moved the button outside of the UpdatePanel but the results were the same.
leskellyAuthor Commented:
Any other thoughts?
Bob LearnedCommented:
That doesn't make any sense.  Are you saying that if you have that line in the event handler, that the event doesn't even get raised?
leskellyAuthor Commented:
Yes that is what I'm saying, however I just noticed something.  For some reason when I republish the app to the server the master page is not being updated.  So when I moved the button outside of the update panel the server did not get this change. I manually copied the master page over and now, with the button outside of the update panel, I get the error below.  If I put the button back inside the panel again nothing happens.


Server Error in '/SupervisorsNotes' Application.

Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Source Error: 



Line 96: 	End Sub
Line 97: 
Line 98: 	Protected Sub btnReport_Click(sender As Object, e As EventArgs) Handles btnReport.Click
Line 99: 		Dim TodayFile As String
Line 100:		Dim FileName As String
  

 Source File:  C:\WebApps\SupervisorsNotes\MasterPages\Site.master.vb    Line:  98 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be loaded.



WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

  

Stack Trace: 



[FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.]
   SupervisorsNotes.Site.btnReport_Click(Object sender, EventArgs e) in C:\WebApps\SupervisorsNotes\MasterPages\Site.master.vb:98
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804

  Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248 

Open in new window

leskellyAuthor Commented:
I manually copied Microsoft.ReportViewer.WebForms.dll to the server and it doesn't give the error however it gives a similar error in regards to 'Microsoft.ReportViewer.Common which isn't even accessed in the app.  The error also references a line of code that is from the handler of a different button.  I wonder if the problem isn't with the publisher.  I'm going to try deleting the app from the server and copying it over manually.
Bob LearnedCommented:
There are 3 files that are needed on the server.  I am looking for the list.  Two of the files are not easily identifiable--although you got the Common file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leskellyAuthor Commented:
After I copied Microsoft.ReportViewer.Common.dll to the bin folder of the app on the server everything worked.  When I restored my original code the report also opened.  Thanks for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.