I've pasted my code below. What I'm trying to do is filter a set of data using the day. The 'day' field is stored as the abbreviated day name, so "thu" for Thursday etc. This works perfectly fine, except once you've changed the date filter to something else, the option for the current day doesn't work.
For example, today is Sunday. When the page loads, it filters out all listings that are not for Sunday, as it should. On a small group of LinkButton controls, if you click any other day of the week, it will change and show the option for the selected day, again, as it should do. However, when you try and set the filter to Sunday again, or click the "today" button, it won't change.
Based on my code, can anyone see what is wrong? If it is of any help, my data is on a remote SQL server.
VB Code:
Dim DateVal As Date = DateTime.UtcNow()
Dim DateName As String = DateVal.ToString("ddd")
Protected Sub btnMon_Click(sender As Object, e As EventArgs) Handles btnMon.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Mon"
End Sub
Protected Sub btnTue_Click(sender As Object, e As EventArgs) Handles btnTue.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Tue"
End Sub
Protected Sub btnWed_Click(sender As Object, e As EventArgs) Handles btnWed.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Wed"
End Sub
Protected Sub btnThu_Click(sender As Object, e As EventArgs) Handles btnThu.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Thu"
End Sub
Protected Sub btnFri_Click(sender As Object, e As EventArgs) Handles btnFri.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Fri"
End Sub
Protected Sub btnSat_Click(sender As Object, e As EventArgs) Handles btnSat.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Sat"
End Sub
Protected Sub btnSun_Click(sender As Object, e As EventArgs) Handles btnSun.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = "Sun"
End Sub
Protected Sub btnAll_Click(sender As Object, e As EventArgs) Handles btnToday.Click
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = DateName
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
SqlDataSource1.SelectParameters("FiltDay").DefaultValue = DateName
End Sub
TSQL (If it helps)
SELECT Schedule.SlotID, RIGHT('00' + CONVERT(VARCHAR(2), Schedule.StartHr), 2) + ':' + RIGHT('00' + CONVERT(VARCHAR(2), Schedule.StartMin), 2) AS StartTime,
Schedule.ProgrammeID, Schedule.Day, RIGHT('00' + CONVERT(VARCHAR(2), Schedule.EndHr), 2) + ':' + RIGHT('00' + CONVERT(VARCHAR(2), Schedule.EndMin), 2)
AS EndTime, Programmes.ProgrammeName, Programmes.Description, Programmes.PresenterID, Presenters.PresenterName, Presenters.PhotoURL
FROM Presenters CROSS JOIN
Programmes CROSS JOIN
Schedule
WHERE (Schedule.Day = #FiltDay)
maybe it is not 100% related to your issue but you should not handle the datasource initialization on the event of a different control.
your need is to fill the sql parameter so you should handle the Selecting event of the datasource.
on click of your buttons set the proper value for your variable DateName and on selecting of the datasource fill the sql parameter using your variable.
acting this way you can easily spot the actual value fed into the call and identify the issue.
Related
I have a form in my application that is used for previewing a report. It has a C1Ribbon at the top which contains navigation buttons, and a C1PrintPreview displaying in a PreviewPane.
I want the navigation buttons in the ribbon (first, previous, next, last), as well as a text box in which to enter a specific page number, to navigate through the preview of the report accordingly. So far, all the documentation and samples I've found have dealt only with adding hyperlinks directly to the report itself...so I'm having a hard time adapting it to my use.
Below is what I have so far...I don't get any build or run-time errors, it just doesn't do anything.
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
Dim nextPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Next)
End Sub
Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
Dim lastPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Last)
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
Dim prevPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Previous)
End Sub
Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
Dim firstPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.First)
End Sub
Private Sub Navigation_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPageNum.KeyDown
If e.Modifiers = Keys.Enter Then
Dim setPage As C1LinkTargetPage = New C1LinkTargetPage(PageJumpTypeEnum.Absolute)
'setPage. = CInt(txtPageNum.Text)
If setPage.PageNo = 0 Then
'what to do if number entered is not a page in document
End If
End If
End Sub
I realize it's likely just because even though I make a C1LinkTargetPage, I don't tell the app what to do with it after that. But I'm not sure how to go about doing that - it's not like there's a "jumptopage" method for the C1PrintPreview (wish it were that easy). Buttons in the ribbon don't have a hyperlink property, so I can't set that when the form loads as in all the samples I found. Not sure where to go from here...
Also I don't even know how I'm supposed to be able to use the Absolute PageJumpTypeEnum...PageNo is read only.
Thank you!
UPDATE 2/25:
I learned that I should be dealing with properties of the Preview Pane...not the C1PrintDocument. With the code below, the navigation buttons and specifying a page number work. My only problem now then is displaying the current page in that page number box. With what I have, PreviewPane.CurrentHistoryEntry just goes to 1 (even if I was on a page other than 1 before-hand).
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
PreviewPane.DoGoNextPage()
End Sub
Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
Dim lastPage As DocumentLocation = New DocumentLocation(report.Pages(report.Pages.Count - 1))
PreviewPane.GotoDocumentLocation(lastPage)
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
PreviewPane.DoGoPreviousPage()
End Sub
Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
Dim firstPage As DocumentLocation = New DocumentLocation(report.Pages(0))
PreviewPane.GotoDocumentLocation(firstPage)
End Sub
Private Sub Navigation_KeyDown(sender As Object, e As KeyEventArgs) Handles txtPageNum.KeyDown
If e.KeyValue = Keys.Enter Then
Dim pageNum As Integer = CInt(txtPageNum.Text)
If (pageNum > 0) And (pageNum <= report.Pages.Count) Then
Dim setPage As DocumentLocation = New DocumentLocation(report.Pages(pageNum - 1))
PreviewPane.GotoDocumentLocation(setPage)
Else
txtPageNum.Text = PreviewPane.CurrentHistoryEntry.ToString
End If
End If
End Sub
They key was "PreviewPane.StartPageIdx"
txtPageNum.Text = (PreviewPane.StartPageIdx + 1).ToString
I have ID Number and name. I am using a datacontrol and this "Select Number, Name from My Table"
I can see both in the combobox, but if I pick one I can't get any data from it. what do I do?
I have used native .NET and get the ID value using this>
Protected Sub lstWorkList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstWorkList.SelectedIndexChanged
Try
Session("gblWorkerNumber") = Me.lstWorkList.SelectedValue.ToString
but in dev express there is no "post back" and I can't get their example to work either.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If (Not IsCallback) Then
CmbCountry.Value = "Mexico" ' I want to get my Number into a session var
FillCityCombo("Mexico")
End If
End Sub
seems to me like their example just hardcodes "Mexico" in ??? how does that work anyway?
Their Example is on this page:
http://demos.devexpress.com/aspxeditorsdemos/ASPxComboBox/ClientAPI.aspx
this is what I was after, the .Value
Protected Sub cbxWorkerName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxWorkerName.SelectedIndexChanged
Session("WorkerNumber") = Me.cbxWorkerName.Value
' in native .NET it is either .selectedindex or .selectedValue one gives the name and the other gives the Number
End Sub
I have a label and timer inside update panel which is also inside script manager. The timer interval was 1000 milliseconds. The label must return the current system date and time and it should be ticking. I used below codes and its working. It returns the current date and time and its ticking too, but the problem is the second/s that ticks skips some seconds. For example: the current time is 09:11:17, after a tick it becomes 09:11:20, it skips 2 seconds.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Label2.Text = Date.Now.ToString
End If
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Label2.Text = Date.Now.ToString
End Sub
What must be the problem in this case?
Thanks in advance.
The following code inserts same data two time in database table, but I want it to insert only one item when button is clicked.
What is the problem in this code?
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
If RadUpload1.UploadedFiles.Count >= 0 Then
Dim file As UploadedFile = RadUpload1.UploadedFiles(0)
SqlDataSource1.InsertParameters("photo").DefaultValue = "./upload/" & file.GetName()
'SqlDataSource1.InsertParameters("name").DefaultValue = TextBox1.Text
SqlDataSource1.Insert()
ListView1.DataBind()
End If
'UpdateProgressContext()
End Sub
You must be using both OnClick="Button1_Click" in your markup and Handles Button1.Click in your procedure.
Try removing one of them.
could anybody advice me, are there any approaches to calculate the methods execution time in asp.net page?
ASP.Net Trace doesn't suit me since it ignores ajax partial postbacks though just they are the tight place.
I have the page event which for some unknown reason executes slowly. Since the logic and event execution chain is rather complicated, I still unable to merely determine the culprit in debugger.
I'd like to measure the execution time of each method throughout the page, but I still see no way but insert redundant code lines (like timeBegin = DateTime.Now.... timeEnd=DateTime.Now = timeBegin etc) in the beginning and ending of each method. It seems to be ugly approach, does anybody know how to do it automatically? Are there tools which measure the methods execution time available?
I am not 100% sure the below works in all cases. So far it does though. Note that Context.Session.Item("CURRENT_WEB_USER") is where I store the current user, and is therefore not readily available as part of the asp.net session variables.
The code hereunder is in replacement of Global.aspx that allows both full page timing and timing of developer code.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub Application_AcquireRequestState(sender As Object, e As System.EventArgs)
If HttpContext.Current Is Nothing Then Return
If HttpContext.Current.Session Is Nothing Then Return
If TypeOf HttpContext.Current.CurrentHandler Is Page Then
If Not Context.Items.Contains("Request_Start_Time") Then
Dim MyPage As Page = HttpContext.Current.CurrentHandler
AddHandler MyPage.Init, AddressOf PageInitEncountered
AddHandler MyPage.Unload, AddressOf PageUnloadEncountered
Context.Items.Add("Request_Start_Time", DateTime.Now)
Dim User As String = Context.Session.Item("CURRENT_WEB_USER")
Context.Items.Add("Request_User", User )
End If
End If
End Sub
Sub Application_ReleaseRequestState(sender As Object, e As System.EventArgs)
If HttpContext.Current Is Nothing Then Return
If TypeOf Context.CurrentHandler Is Page Then
Dim Page As Page = Context.CurrentHandler
Dim StartDate As Date = Context.Items("Request_Start_Time") : If StartDate = Nothing Then Return
Dim EndDate As Date = Now
Dim StartProc As Date = Context.Items("Page_Init")
Dim EndProc As Date = Context.Items("Page_Unload")
Dim User As String = Context.Items("Request_User")
LogEntry(StartDate, EndDate, StartProc, EndProc, User, Context.Request.Url.ToString)
End If
End Sub
Public Sub PageInitEncountered(sender As Object, e As System.EventArgs)
Context.Items.Add("Page_Init", DateTime.Now)
End Sub
Public Sub PageUnloadEncountered(sender As Object, e As System.EventArgs)
Context.Items.Add("Page_Unload", DateTime.Now)
End Sub
Public Sub LogEntry(StartDate As Date, EndDate As Date, StartProc As Date, EndProc As Date, User As String, PageURL As String)
System.Diagnostics.Debug.WriteLine(" (" & LogEntry.RequestMs & " - " & LogEntry.DurationMs & ") (" & User & ") " & PageURL)
End Sub
This may not be what you are looking for, but RedGate has a product called Performance Profiler that does exactly that. They do have a 15 day trial so you can even download it and try it out on your current issue. IMHO, it's worth every penny.
You can use asp.net performance counters and other things also. But that will not measure a page speed but they will measure a over all application performance.