Infinite Loop with ReportViewer and Global.System.Diagnostics.DebuggerNonUserCodeAttribute - asp.net

I've written a simple webForm that contains 1 textbox and a ReportViewer (created by Reoprt Wizard). I'm receiving no errors when attempting to execute the report, but the report never stops loading. I've double checked the .rdlc file (by previewing the .xsd file and it displays the expected data. So, I set up a breakpoint in my code behind to see if I could identify the problem. Somehow, the code successfully completes and refreshes the ReportViewer code, and then goes into a Designer.vb file to run 4 functions, and then back to the ReportViewer code again. I don't understand what is happening in the Designer.vb code. Could someone please help me understand what I've done wrong? I'll include the ASP.net, vb code behind, and the 4 blocks of code from the Designer.vb file.
ASP.net Code:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/HRMaster.Master" CodeBehind="VacationSick_EmployeeReportByArea.aspx.vb" Inherits="CEI_PerformanceReviews.VacationSick_EmployeeReportByArea" %>
<%# Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HRPlaceHolder" runat="server">
<asp:Label ID="Label2" runat="server" style="z-index: 1; left: 74px; top: 215px; position: absolute" Text="Year:"></asp:Label>
<p>
</p>
<asp:DropDownList ID="ddl_Year" runat="server" DataSourceID="YearChooser" DataTextField="PeriodYYYY" DataValueField="PeriodYYYY" style="z-index: 1; left: 129px; top: 214px; position: absolute">
</asp:DropDownList>
<asp:SqlDataSource ID="YearChooser" runat="server" ConnectionString="<%$ ConnectionStrings:CafeWorksConnectionString %>" SelectCommand="SELECT DISTINCT PeriodYYYY
FROM Ted.CafeWorks.dbo.FatzPeriodDates
WHERE PeriodYYYY >= (DATEPART(YEAR, GetDate())-2)
ORDER BY PeriodYYYY DESC"></asp:SqlDataSource>
<asp:Button ID="btn_Refresh" runat="server" style="z-index: 1; left: 269px; top: 212px; position: absolute" Text="Refresh" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="XX-Large" ForeColor="#000099" style="z-index: 1; left: 0px; top: 142px; position: absolute; width: 1179px; text-align: center" Text="Employee Vacation/Sick Days by Area Report"></asp:Label>
<rsweb:ReportViewer ID="rv_EmployeeReportByArea" runat="server" Font-Names="Verdana" Font-Size="8pt" style="z-index: 1; left: 29px; top: 280px; position: absolute; height: 400px; width: 710px" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
<LocalReport ReportEmbeddedResource="CEI_PerformanceReviews.VacationSick_ReportByArea.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="Dilbert_VacationSickByArea" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetData" TypeName="CEI_PerformanceReviews.Dilbert_VacationSickByAreaTableAdapters.VacationSick_CalculationsByAreaProcTableAdapter" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_Year" DefaultValue="2014" Name="Year" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="CEI_PerformanceReviews.Dilbert_VacationSickByAreaTableAdapters.VacationSick_CalculationsByAreaProcTableAdapter" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:ControlParameter ControlID="ddl_Year" Name="Year" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</asp:Content>
VB Code Behind:
Imports Microsoft.Reporting.WebForms
Public Class VacationSick_EmployeeReportByArea
Inherits System.Web.UI.Page
'Declare Variables
Dim Choose_Year As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Default the Year in ddl to this year
If (Page.IsPostBack) = False Then
ddl_Year.SelectedValue = Now.Year
End If
'When the page loads, fill the report with the current year's data
Choose_Year = ddl_Year.SelectedValue.ToString()
rv_EmployeeReportByArea.LocalReport.ReportPath = "VacationSick\VacationSick_ReportByArea.rdlc"
Dim Param As New ReportParameter("Year", "2014")
rv_EmployeeReportByArea.LocalReport.SetParameters({Param})
rv_EmployeeReportByArea.ServerReport.Refresh()
End Sub
These 4 Code Blocks from the file Dilbert_VacationSickByArea.Designer.vb are executed and then it goes back to the PageLoad code for the ReportViewer:
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Public Property ClearBeforeFill() As Boolean
Get
Return Me._clearBeforeFill
End Get
Set
Me._clearBeforeFill = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected ReadOnly Property CommandCollection() As Global.System.Data.SqlClient.SqlCommand()
Get
If (Me._commandCollection Is Nothing) Then
Me.InitCommandCollection
End If
Return Me._commandCollection
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")> _
Protected Friend ReadOnly Property Adapter() As Global.System.Data.SqlClient.SqlDataAdapter
Get
If (Me._adapter Is Nothing) Then
Me.InitAdapter
End If
Return Me._adapter
End Get
End Property

Try printing your report only If Not Me.Page.IsPostBack.
You can also remove rv_EmployeeReportByArea.ServerReport.Refresh() because you're using a LocalReport.

Related

ASP TImer, UpdatePanel and UpdatePanelAnimationExtender

When I make use of the Timer event tick to trigger an animated update panel refresh I get the following error:
TypeError: sender._activeElement is undefined
Sys.Extended.UI.Animation.UpdatePanelAnimationBehavior.prototype._partialUpdateBeginRequest()
ScriptResource.axd:75
Function$createDelegate/<()
ScriptResource.axd:47
Sys$EventHandlerList$getHandler/<()
ScriptResource.axd:3484
Sys$WebForms$PageRequestManager$_onFormSubmit()
ScriptResource.axd:1284
Sys$WebForms$PageRequestManager$_doPostBack()
ScriptResource.axd:824
Function$createDelegate/<()
ScriptResource.axd:47
Sys$UI$_Timer$_doPostback()
ScriptResource.axd:60
Sys$UI$_Timer$_raiseTick()
ScriptResource.axd:91
Function$createDelegate/<()
If I use a button click event it works fine animations and all, but I need it timed. If I remove the UpdatePanelAnimationExtender the timer refresh works fine but I don't get the animations.
I am using Ajax Control Toolkit 16.
<%# Page Language="VB" AutoEventWireup="True" CodeFile="Test2.aspx.vb" Inherits="_Default" Debug="True" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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></title>
<link href="ds2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
<div><div style="float:right; color:gray;"><asp:Label Visible="true" ID="Label1" runat="server" Text="1"></asp:Label></div>
<ajaxToolkit:UpdatePanelAnimationExtender ID="UpdatePanelAnimationExtender1" runat="server" TargetControlID="logoUpdatePanel">
<Animations><OnUpdating><Sequence>
<EnableAction AnimationTarget="effect_color" Enabled="true" />
<EnableAction AnimationTarget="effect_collapse" Enabled="true" />
<EnableAction AnimationTarget="effect_fade" Enabled="true" />
<Parallel Duration="1" Fps="20">
<FadeOut AnimationTarget="PanelInfo" minimumOpacity=".2" />
<color AnimationTarget="PanelInfo" StartValue="#FFEF3F" EndValue="#FFFFFF" Property="style" PropertyKey="backgroundColor" />
</Parallel></Sequence></OnUpdating>
<OnUpdated>
<Sequence>
<EnableAction AnimationTarget="effect_collapse" Enabled="true" />
<EnableAction AnimationTarget="effect_fade" Enabled="true" />
<Parallel Duration="1" Fps="20">
<FadeIn AnimationTarget="logoUpdatePanel" />
<Resize Height="0" />
</Parallel>
</Sequence>
</OnUpdated></Animations>
</ajaxToolkit:UpdatePanelAnimationExtender>
<asp:UpdatePanel ID="logoUpdatePanel" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Image ID="Logo1" runat="server" ImageUrl="~/Images/RBCCCW_1080p_Horizontal.jpg" ImageAlign="Middle" />
<asp:Label Visible="false" runat="server" ID="TableCount" Text="tablecount"></asp:Label>
<asp:Label visible="false" runat="server" ID="rowcount" Text="rowcount"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" updatemode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="bindlist"></asp:Timer>
<asp:DataList ID="RoomEventsList" runat="server" Width="1080px" CellPadding="10" CellSpacing="5" HeaderStyle-BackColor="#0060AA" AlternatingItemStyle-BackColor="#a8cde2" Font-Size="24pt">
<HeaderTemplate>
<div class="colhead1">Start</div><div class="colhead2">Events</div>
</HeaderTemplate>
<ItemTemplate>
<div class="col1"><%#Eval("fstf").ToString.ToLower()%></div><div class="col2"><span style="font-weight:bold"><%#Eval("EV700_ALT_FUNC_DESC")%></span> <br /><span style="float:right;font-size:22pt"> <%#Eval("EV800_SPACE_DESC")%> | <%#Eval("EV812_HIER_LVL2_DESC")%> | <%#Eval("EV811_HIER_LVL1_DESC")%> </span></div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
<table width="100%"><tr><td></td><td align="right">
<asp:Label Visible="false" runat="server" ID="pagenumber" Text="start"></asp:Label><asp:Label Visible="false" ID="lblTotalPages" runat="server" Text="1"></asp:Label></td></tr></table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
and the code behind:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Collections.Generic
Imports System.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Dim pagedDSr As New PagedDataSource()
Dim totalPages As Integer
Dim totalImages As Integer
Public Property CurrentPage() As Integer
Get
Return IIf(ViewState("CurrentPage") Is Nothing, 0, CInt(ViewState("CurrentPage")))
End Get
Set(value As Integer)
ViewState("CurrentPage") = value
End Set
End Property
Public Property imagecount() As Integer
Get
Return IIf(ViewState("imagecount") Is Nothing, 0, CInt(ViewState("imagecount")))
End Get
Set(value As Integer)
ViewState("imagecount") = value
End Set
End Property
Public Property imageSize() As String
Get
Return IIf(ViewState("imageSize") Is Nothing, "", CStr(ViewState("imageSize")))
End Get
Set(value As String)
ViewState("imageSize") = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack() Then
CurrentPage = 0
imagecount = 1
TableCount.Text = "0"
bindlist()
End If
End Sub
Sub changelogo()
Logo1.ImageUrl = "~/Images/" & imagesize & "/" & imagecount & ".jpg"
If imagecount = IO.Directory.GetFiles("C:\inetpub\digsignall\Images\" & imageSize & "\", "*.jpg").Length Then
imagecount = 1
TableCount.Text = imagecount.ToString
Else
imagecount = imagecount + 1
TableCount.Text = imagecount.ToString
End If
End Sub
Sub bindlist()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ebmsprodCS").ConnectionString
Dim con As New SqlConnection(strConnString)
Using conn As New SqlConnection(strConnString)
Dim varname1 As New System.Text.StringBuilder
varname1.Append("SELECT statement removed for space")
Dim cmd As New SqlCommand(varname1.ToString, conn)
cmd.CommandType = CommandType.Text
conn.Open()
'Dim drEvents As SqlDataReader = cmd.ExecuteReader()
Dim eventsda = New SqlDataAdapter(cmd)
Dim ds = New DataSet
eventsda.Fill(ds, "events")
If ds.Tables(0).Rows.Count <= 0 Then
RoomEventsList.Visible = False
imagesize = "fullscreen"
rowcount.Text = IO.Directory.GetFiles("C:\inetpub\digsignall\Images\" & imageSize & "\", "*.jpg").Length
changelogo()
Else
RoomEventsList.Visible = True
imageSize = "top"
changelogo()
End If
pagedDSr.DataSource = ds.Tables(0).DefaultView
pagedDSr.AllowPaging = True
pagedDSr.PageSize = 10
pagedDSr.CurrentPageIndex = CurrentPage
totalPages = pagedDSr.PageCount
RoomEventsList.DataSource = pagedDSr
RoomEventsList.DataBind()
conn.Close()
Label1.Text = Request.QueryString("room")
End Using
If pagedDSr.IsLastPage Then
CurrentPage = 0
Else
CurrentPage = CurrentPage + 1
End If
pagenumber.Text = CurrentPage.ToString
End Sub
Protected Sub bindlist_tick()
pagedDSr.CurrentPageIndex = CurrentPage
RoomEventsList.DataSource = pagedDSr
RoomEventsList.DataBind()
If pagedDSr.IsLastPage Then
CurrentPage = 0
Else
CurrentPage = CurrentPage + 1
End If
pagenumber.Text = CurrentPage.ToString
End Sub
End Class

Error when sorting a dropdownlist on webpage

I have a webpage that won't let me sort a dropdownlist. I have a SQLDataSource connection configured to bring up the rows Description in the table tblCodesWorkNotRec. When I go to Order By and choose sort by Description, and then test the query, I'm getting an error -
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
Why?
If you need to see code, what code - aspx or vb?
Here is the vb code:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Mvc
Partial Class TimeOffAddNoRequest
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Once data is edited on this webpage, do not go back to first loaded data (data from gridview)
If Page.IsPostBack = True Then
Return
End If
Dim windowsLoginName As System.String = HttpContext.Current.User.Identity.Name 'System.Security.Principal.WindowsIdentity.GetCurrent().Name
Dim split As String() = Nothing
Dim vname As String
Dim sqlConnection As New SqlConnection("Data Source=janetdev;Initial Catalog=TimeSQL;Persist Security Info=True;User ID=sa;Password=password")
Dim cmd, cmd1, cmd2 As New SqlCommand
Dim returnValue, returnValue1, returnValue2 As Object
Dim dt As Date
dt = Today
MsgBox(Today)
'Get network login name (name only)
split = windowsLoginName.Split("\".ToCharArray)
vname = split(1)
'Get firstname from tblEmployees that matches login name
cmd.CommandText = "SELECT FirstName FROM tblEmployees where login = '" & vname & "'"
cmd.CommandType = CommandType.Text
cmd.Connection = sqlConnection
'Get lastname from tblEmployees that matches login name
cmd1.CommandText = "SELECT LastName FROM tblEmployees where login = '" & vname & "'"
cmd1.CommandType = CommandType.Text
cmd1.Connection = sqlConnection
'Get employeeid from tblEmployees that matches login name
cmd2.CommandText = "SELECT EmployeeID FROM tblEmployees where login = '" & vname & "'"
cmd2.CommandType = CommandType.Text
cmd2.Connection = sqlConnection
sqlConnection.Open()
'firstname
returnValue = cmd.ExecuteScalar()
'lastname
returnValue1 = cmd1.ExecuteScalar()
'employeeid
returnValue2 = cmd2.ExecuteScalar()
sqlConnection.Close()
'display firstname and lastname on screen
TextBox3.Text = returnValue & " " & returnValue1
TextBox4.Text = returnValue2
'display today's date
DateRequested.Text = dt
'Get value of other fields
If Not [String].IsNullOrEmpty(Request.QueryString("BeginDateOff").ToString()) Then
'Retrieving the BeginDateOff Value
BeginDate.Text = Request.QueryString("BeginDateOff").ToString()
End If
If Not [String].IsNullOrEmpty(Request.QueryString("EndDateOff").ToString()) Then
'Retrieving the EndDateOff Value
EndDate.Text = Request.QueryString("EndDateOff").ToString()
End If
If Not [String].IsNullOrEmpty(Request.QueryString("BeginTimeOff").ToString()) Then
'Retrieving the BeginTimeOff Value
BeginTimeDD.SelectedValue = Request.QueryString("BeginTimeOff").ToString
End If
If Not [String].IsNullOrEmpty(Request.QueryString("EndTimeOff").ToString()) Then
'Retrieving the EndTimeOff Value
EndTimeDD.Text = Request.QueryString("EndTimeOff").ToString()
End If
'Retrieving the All Day Value
AllDay.Checked = Boolean.Parse(Request.QueryString("AllDay_YesNo"))
'AllDay.Checked = Request.QueryString("AllDay_YesNo")
'Retrieving the WorkHoursNotRecordID
wkid.Text = Request.QueryString("WorkHoursNotRecordID").ToString()
If Request.QueryString("description").ToString = "Unknown" Then
Label2.Text = "You must change the reason from Unknown."
DropDownList2.Focus()
Exit Sub
Else
'Retrieving the Description Value
DropDownList2.Text = Request.QueryString("Description").ToString()
End If
BeginDate.Focus()
End Sub
And here is the aspx code:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="TimeOffAddNoRequest.aspx.vb" Inherits="timework.TimeOffAddNoRequest" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ToolkitScriptManager ID="toolkitScriptManager" runat="server" />
<asp:Label ID="Label2" runat="server"
style="color: #990033; font-weight: 700"></asp:Label>
<asp:Label ID="Label1" runat="server"
style="color: #000099; font-weight: 700"></asp:Label>
<br />
<label>Employee Name:</label><asp:TextBox ID="TextBox3" runat="server" BorderStyle="None"
style="margin-left: 7px; font-size: medium; font-weight: 700;"
Width="150px" Height="22px" AutoPostBack="True"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server" Width="129px"
AutoPostBack="True" Visible="False"></asp:TextBox>
<br />
<hr align="left" style="width: 791px; margin-left: 0px" />
<label>Date Requested:<asp:TextBox ID="DateRequested" runat="server" style="margin-left: 9px; font-size: medium; font-weight: 500;"
Width="150px" Height="22px" AutoPostBack="True" BorderStyle="None"></asp:TextBox>
</label>
<br />
<br />
<label>Begin Date Off:</label>
<asp:TextBox ID="BeginDate" runat="server" style="margin-left: 10px; font-size: medium; font-weight: 500;"
Width="150px" Height="22px" AutoPostBack="True" BorderStyle="Solid"
BorderWidth="1px"></asp:TextBox>
<label> End Date Off:</label>
<asp:TextBox ID="EndDate" runat="server" style="margin-left: 15px; font-size: medium; font-weight: 500;"
Width="150px" Height="22px" AutoPostBack="True" BorderStyle="Solid"
BorderWidth="1px"></asp:TextBox>
<br />
<br />
<label> All Day?</label>
<asp:CheckBox ID="AllDay" runat="server" AutoPostBack="True" />
<label> Begin Time Off:</label> <label>
<asp:DropDownList ID="BeginTimeDD" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Time" DataValueField="Time"
Height="26px" Width="100px">
</asp:DropDownList>
End Time Off:</label> <asp:DropDownList ID="EndTimeDD"
runat="server" DataSourceID="SqlDataSource1" DataTextField="Time"
DataValueField="Time" Height="26px" Width="100px">
</asp:DropDownList>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TimeSQLConnectionString2 %>"
SelectCommand="SELECT [Time] FROM [tblCodesTime] ORDER BY [Time]">
</asp:SqlDataSource>
<label> Reason:</label>
<asp:DropDownList
ID="DropDownList2" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="Description"
DataValueField="Description" Height="26px" Width="149px">
</asp:DropDownList>
<br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:TimeSQLConnectionString1 %>"
SelectCommand="SELECT [Description] FROM [tblCodesWorkNotRec] ORDER BY [Description]">
</asp:SqlDataSource>
<asp:TextBox ID="wkid" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" Text="Save" />
<br />
<br />
</asp:Content>
I believe your error is in your aspx on this line
SELECT [Description] FROM [tblCodesWorkNotRec] ORDER BY [Description]
The order by description is going to be what is giving you that error. You can fix this by casting to a varchar:
SELECT [Description]
FROM [tblCodesWorkNotRec]
ORDER BY Convert(varchar(max), [Description])
I'm not sure why you would want to order by a description field however. Perhaps its best just to do away with the order by. The error may also have occured on the order by [time] line. But if this is a DateTime field its fine. This field should probably be renamed to something that is not a keyword, like CodeTime
Some other notes on your code, Refactoring this is a good idea.
As a recommendation, I would make a single class that talks to your database. Dont put sql connections in your code behind, much less in your aspx. (if you are going to do that, pick one location, not both) This class will have all your sql and returns just the values you want.
Consolidate your sql. There is no reason to make 3 calls to the same table to get one value from each call. Make one call to get 3 things. I'm speaking of the firstname, lastname, employeeid calls.
Dont put business logic in event handlers. Notice your Page_Load method. This is an event handler. Any code that you put here cannot be called from somewhere else, so you end up copying code over and over. Simply move the calls to their own method, and call that method from Page_Load. (GoF pattern - Facade)
Put your UI elements in their own div tag and align them with CSS. Get rid of (or at least think hard about) the <br/> and markup and use things like margin in css to move your elements around. Also move all the inline style tags to css.

Assigning FormView value to VB variable

I am trying to assign a FormView value to a VB variable.
I am using code that works fine when first_nameTextBox is a TextBox and user enters data directly, but fails when first_nameTextBox is a label populated from a database via FormView.
Error I receive is BC30451: 'FormView2_first_nameTextBox' is not declared. It may be inaccessible due to its protection level.
Any help much appreciated.
The code is below;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# Page Language="VB" %>
<%# Import Namespace="System.Net.Mail" %>
<%# Import Namespace="System.Text" %>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
<head runat="server">
<!-- Scripting area here -->
<script runat="server" type="text/vbscript">
Protected Sub btnSubmit_click (ByVal sender As Object, ByVal e As EventArgs)
If IsPostBack Then
Dim sc As SmtpClient = New SmtpClient("relay.hostinguk.net")
Dim sb As StringBuilder = New StringBuilder()
Dim msg As MailMessage = Nothing
sb.Append("Name : " + FormView2_first_nameTextBox.Text + vbCrLf)
Try
msg = New MailMessage("from#company.com", _
"to#company.com", "Contact details for Co", _
sb.ToString())
sc.Send(msg)
Catch ex As Exception
' something bad happened
Response.Write("Something bad happened! - please try again")
Finally
Multiview1.SetActiveView(ViewConfirmation)
If Not msg Is Nothing Then msg.Dispose()
End Try
End If
End Sub
Protected Sub Page_Load (ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Try
Multiview1.SetActiveView(ViewForm)
Catch ex As Exception
' something bad happened
Response.Write("Something bad happened! - please try again")
End Try
End If
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:MultiView runat="server" id="MultiView1">
<asp:View runat="server" id="ViewForm">
<asp:AccessDataSource ID="AccessDataSource2bd" runat="server" DataFile="../app_data/bw_data.mdb" SelectCommand="SELECT * FROM student WHERE student_ID = 92">
</asp:AccessDataSource>
<asp:FormView runat="server" id="FormView2" DataSourceID="AccessDataSource2bd" DataKeyNames="student_ID" DefaultMode="ReadOnly">
<ItemTemplate >
<asp:Label id="first_nameTextBox" runat="server" Text='<%# Eval("first_name") %>' />,
</ItemTemplate >
</asp:FormView>
<asp:Table runat="server" id="Table2">
<asp:TableRow runat="server">
<asp:TableCell runat="server" HorizontalAlign="Left" height="20px">
<asp:Button id="UpdateButton" runat="server" CommandName="Update" onclick="btnSubmit_click" Text="Send Email"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:View>
<asp:View runat="server" id="ViewConfirmation">
<p>An email has been sent, and copied to you, confirming all current contact details.</p>
</asp:View>
<p></p>
</asp:MultiView>
</form>
</body>
</html>
Thanks
Ant
Try this:
dim tb as TextBox = FormView2.Row.FindControl("first_nameTextBox")
sb.Append("Name : " + tb.Text + vbCrLf)

Missing Source code of a published ASP.NET application

I have a web application that is published and working in server. I have aspx files, but I don't have .vb files. I need to edit a singe page in the application. How can I reach to the .vb files ? or better to say that how can I edit the part that I want in the application?
Edit:
Here is my aspx file:
<%# page language="VB" autoeventwireup="false" inherits="UrunRapor, App_Web_hfev-r-q" %>
<%# Register assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %><%# Register assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %>
<%# Register assembly="DevExpress.Web.ASPxEditors.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>
<%# Register assembly="DevExpress.Web.ASPxGridView.v8.3.Export, Version=8.3.6.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxGridView.Export" tagprefix="dxwgv" %>
<!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>Ürün Detaylı Rapor</title>
<script language="javascript">
window.moveTo(0, 0);
window.resizeTo(screen.availWidth, screen.availHeight);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="font-size: 9pt; width: 474px; font-family: Calibri">
<tr>
<td style="width: 100px; height: 22px">
Ay</td>
<td style="width: 100px; height: 22px">
<asp:DropDownList ID="cboMonth" runat="server" BackColor="#FFFFC0" Font-Bold="True"
Font-Names="Calibri" Font-Size="9pt">
<asp:ListItem Selected="True" Value="%%">[..]</asp:ListItem>
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="05">May</asp:ListItem>
<asp:ListItem Value="06">June</asp:ListItem>
<asp:ListItem Value="07">July</asp:ListItem>
<asp:ListItem Value="08">August</asp:ListItem>
<asp:ListItem Value="09">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px; height: 22px">
Yıl
</td>
<td style="width: 100px; height: 22px">
<asp:DropDownList ID="cboYear" runat="server" BackColor="#FFFFC0" Font-Bold="True"
Font-Names="Calibri" Font-Size="9pt">
<asp:ListItem Selected="True" Value="%%">[..]</asp:ListItem>
<asp:ListItem Value="2007">2007</asp:ListItem>
<asp:ListItem Value="2008">2008</asp:ListItem>
<asp:ListItem Value="2009">2009</asp:ListItem>
<asp:ListItem Value="2010">2010</asp:ListItem>
<asp:ListItem>2011</asp:ListItem>
<asp:ListItem>2012</asp:ListItem>
<asp:ListItem>2013</asp:ListItem>
<asp:ListItem>2014</asp:ListItem>
<asp:ListItem>2015</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px; height: 22px">
<asp:Button ID="Button1" runat="server" Font-Bold="True" Font-Names="Calibri" Font-Size="9pt"
Text="Sorgula" /></td>
<td style="width: 100px; height: 22px">
<asp:Button ID="Button2" runat="server" Font-Bold="True" Font-Names="Calibri" Font-Size="9pt"
Text="Excel'e aktar" /></td>
<td style="width: 100px; height: 22px">
<asp:Button ID="Button3" runat="server" Font-Bold="True" Font-Names="Calibri" Font-Size="9pt"
Text="PDF dosyasına aktar" Width="123px" /></td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CRRConnectionString %>">
<SelectParameters>
<asp:ControlParameter ControlID="cboMonth" Name="Month" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="cboYear" Name="Year" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<dxwgv:aspxgridview id="dgCRR" runat="server" datasourceid="SqlDataSource1">
<Settings ShowFilterRow="True" ShowFilterRowMenu="True" ShowFilterBar="Visible"
ShowGroupedColumns="True" ShowGroupPanel="True"></Settings>
<SettingsPager Visible="False" PageSize="1000" Position="TopAndBottom"></SettingsPager>
</dxwgv:aspxgridview>
<dxwgv:ASPxGridViewExporter ID="ToExcel" runat="server">
</dxwgv:ASPxGridViewExporter>
</form>
</body>
</html>
Her is my .vb file which I want to use
Imports System.Globalization
Partial Class UrunRapor
Inherits CRR.RequestBase
Dim SelCmd As String
Dim MyUser As String
Dim dtreg As Data.DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyUser = Request.ServerVariables.Get("LOGON_USER")
If Not Page.IsPostBack Then
Dim dareg As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter
dareg.SelectCommand = select_User(Request.ServerVariables.Get("LOGON_USER"))
dareg.SelectCommand.Connection = cnn
dtreg = New Data.DataTable
dareg.Fill(dtreg)
If dtreg.Rows.Count = 0 Then
Response.Redirect("NotAuthRep.aspx")
End If
'Exit Sub
'dgCRR.DataBind()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
FillGrid()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
FillGrid()
ToExcel.FileName = "CRR-Product.pdf"
ToExcel.WritePdfToResponse("CRR-Product.pdf")
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
'ToExcel.FileName = "CRRNew"
'ToExcel.DataBind()
FillGrid()
ToExcel.GridViewID = "dgCRR"
ToExcel.WriteXlsToResponse()
End Sub
Protected Sub FillGrid()
SelCmd = "SELECT tblCRRProductDetails.CRRId, tblCRRProductDetails.ProductCode, tblCRRProductDetails.ProductName, tblCRRProductDetails.Batch, tblCRRProductDetails.ExpireDate, tblCRRProductDetails.Qty, tblCRRProductDetails.SalesUnit, tblCRR.CrrCaptureDate, tblCRR.RegistrarName, tblCRR.CustomerCode, tblCRR.CustomerName, tblCRR.Channel, tblCRR.ClaimerName, tblCRR.ClaimerAddress, tblCRR.ClaimerPhone, tblCRR.ClaimerMail, tblCRR.CaseDetails, tblCRR.RsDeptName, tblCRR.ReasonName, tblCRR.RsPerName, tblCRR.ExpecRsDay, tblCRR.ExpecRsDate, tblCRR.RsDescription, tblCRR.ResolutionDate, tblCRR.ClaimResult, tblCRR.ActionPlan, tblCRR.ClosedPerName, tblCRR.ClosingDate,tblCRR.Status FROM tblCRRProductDetails INNER JOIN tblCRR ON tblCRRProductDetails.CRRId = tblCRR.CrrID WHERE (MONTH(CrrReceiveDate) LIKE '" & cboMonth.SelectedItem.Value & "') AND (YEAR(CrrReceiveDate) LIKE '" & cboYear.SelectedItem.Value & "')"
SqlDataSource1.ConnectionString = "My Connection String"
SqlDataSource1.SelectCommand = SelCmd
dgCRR.DataBind()
End Sub
End Class
When you publish the site, the compiled version is published on the server, not the code files. You would need Disassembler / Decompiler to decompile the dll files. Some of them are
.Net Reflecter
ILSpy (Free)
Dot Peek (Free)
What you could do is change the ASPX, so for example instead of this:
<%# Page Language="C#" CodeBehind="MyPage.aspx.cs" Inherits="MyNamespace.MyPage" %>
You could change it like this:
<%# Page Language="C#" Inherits="MyOtherNamespace.MyNewPage" %>
Write the new behavior in a new MyOtherNamespace.MyNewPage class (that should derive at least from System.Web.UI.Page) that you can put in any .DLL assembly that you deploy in the bin directory.
You can also derive this new class from the original page (just reference the original assembly) instead of just deriving from System.Web.UI.Page, if deriving is an option for you, depending on the changes you need to do.
Otherwise, you will have to reconstruct the original code using a tool such as .NET Reflector or ILSpy to build this new class, but at least, you don't have to touch the existing compiled assembly.
You could try disassembling it using ilasm and editing the IL directly, but I think realistically you will struggle to make any changes without the source. The .cs files are the source files. Only the compiled IL files will be available on the published site. You will need to find out who published it and speak to them about getting the source.

Passing a variable to a dynamic dropdownlist

I have 2 dropdownlists, one is State and the second is City. I am trying to create it so, when a user clicks the State, the second dropdownlist is populated with City names from a datatable.
Here is the code
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<%--<cc2:CascadingDropDown ID="CascadingDropDown1" runat="server"> </cc2:CascadingDropDown>--%>
<h1>Live Event Search Engine</h1><br />
State: <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="ST_Code" DataValueField="ST_Code" /><asp:SqlDataSource
ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnection %>"
SelectCommand="SELECT [ST_Code] FROM [State]">
</asp:SqlDataSource>
City: <asp:DropDownList ID="ddlCity" runat="server" DataSourceID="SqlDataSource2" DataTextField="RS_City" DataValueField="RS_City" /><asp:SqlDataSource
ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnection %>"
SelectCommand="web_PublicProgramListbyState" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="State" SessionField="ST_Code" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Button ID="Submit" runat="server" Text="Submit" />
</asp:Content>
and the code behind is
Public Sub ddlState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
Me.ddlCity.Items.Clear()
Dim da As New SqlDataAdapter("web_PublicProgramListbyState", New SqlConnection(ConfigurationManager.AppSettings("dbConnection")))
Dim ds As New DataSet
da.Fill(ds, "#State")
da.Dispose()
Me.ddlCity.DataSource = ds.Tables("Products")
Me.ddlCity.DataTextField = "ProductName"
Me.ddlCity.DataValueField = "ProductID"
Me.ddlCity.DataBind()
End Sub
End Class
Looks like you are trying to bring a dataset into this when you already have a SqlDataSource defined. Just modify the parameters of the SqlDataSource and re-bind:
Public Sub ddlState_SelectedIndexChanged(...)
SqlDataSource2.SelectParameters.Clear()
SqlDataSource2.SelectParameters.Add(New Parameter("#State", DbType.String, ddlState.SelectedValue))
ddlCity.DataBind()
End Sub
Edit: Or you can use a ControlParameter referencing ddlState.SelectedValue in SqlDataSource2.SelectParameters as mentioned in another answer. Only trick there is you have to manage your default values carefully so ddlCity only binds when you want it to.
I would change it to a control param and just call the databind. No need to do the fill yourself.
<asp:ControlParameter Name="State" ControlID="ddlState" Type="String" />
and then in the select event just call:
Me.ddlCity.DataBind()
Or if you want to remove the codebehind all together put it in an update panel with a trigger.
I don't see where the ddlState_SelectedIndexChanged event writes the session variable. This is required.

Resources