Jump to Page in C1PrintDocument - report

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

Related

VB.NET display label text only on default.aspx page only

Have a message that currently displays on every page of our website. I'd like to change this so that it only appears on the homepage which is default.aspx. Please let me know what I can try. the below code lives in the code behind of the master page of the site. We use vb.net but if someone can write it in C# I can convert it.
Previous code that displays label text on every page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using ds As DataSet = SystemDataObject.SystemDataGetMessage()
lblSystemMessage.Text = ds.Tables(0).Rows(0)("SystemMessage_sd").ToString
End Using
End Sub
Code I have written that isn't working, what am I missing?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using ds As DataSet = SystemDataObject.SystemDataGetMessage()
Dim appPath As String = Request.PhysicalApplicationPath
If appPath = "/Default.aspx" Then
lblSystemMessage.Text = ds.Tables(0).Rows(0)("SystemMessage_sd").ToString
End If
End Using
End Sub
Ended up wrapping the control in a panel with ID of Message and using the following code to display only if on the homepage.
If Page.Title = "Home" Then
Message.Visible = True
Else
Message.Visible = False
End If

Getting the text from a label inside a List View VB

I am trying to retrieve the text from a Label within a List View control. The method I am using, below, will only retrieve the first piece of text I want. The text I am looking for is an ID, therefore I am always returning the first ID no matter what item I click on.
Private Sub guidelinesList_SelectedIndexChanged(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles guidelinesList.SelectedIndexChanged
i = guidelinesList.SelectedIndex
End Sub
Private Sub guidelinesList_ItemDataCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles guidelinesList.ItemCommand
Dim theIdLabel As Label = CType(guidelinesList.Items(i).FindControl("lblId"), Label)
guidelinesId = CInt(theIdLabel.Text)
If String.Equals(e.CommandName, "bEdit") Then
Response.Redirect("../EditFile.aspx?FileId=" & guidelinesId & "&FileType=Guidelines" & "&AppType=Payroll")
End If
End Sub
Small code change is all that was needed, see below.
Private Sub guidelinesList_ItemDataCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles guidelinesList.ItemCommand
If String.Equals(e.CommandName, "bEdit") Then
Dim i As Integer = CInt(e.Item.DataItemIndex)
Dim theIdLabel As Label = CType(guidelinesList.Items(i).FindControl("lblId"), Label)
guidelinesId = CInt(theIdLabel.Text)
Response.Redirect("../EditFile.aspx?FileId=" & guidelinesId & "&FileType=Guidelines" & "&AppType=Payroll")
End If
End Sub

Object reference not set to an instance of an object in ASP(vb)

I came across to this code that creates control dynamically. I tried it. However, whenever I run it, Object reference not set to an instance of an object error pops out and points out to a certain line in the code( i put ---> on the line). I'm a newbie in this programming language. I don't know what to do.
Here's the code I got:
Imports System.Collections.Generic
'Imports System.Data.Odbc
Partial Public Class main
Inherits System.Web.UI.Page
Private controlCounter As Integer = 0
Private myControlList As List(Of String)
Protected Overrides Sub LoadViewState(ByVal savedState As Object)
MyBase.LoadViewState(savedState)
myControlList = DirectCast(ViewState("myControlList"), List(Of String))
For Each ctlID As String In myControlList
controlCounter += 1
Dim hyper As New HyperLink()
hyper.ID = ctlID
Dim lineBreak As New LiteralControl("<br />")
PlaceHolder1.Controls.Add(hyper)
PlaceHolder1.Controls.Add(lineBreak)
Next
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
myControlList = New List(Of String)()
ViewState("myControlList") = myControlList
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
controlCounter += 1
Dim hyper As New HyperLink()
hyper.Text = "a new text Box"
hyper.ID = "hyperlink" + controlCounter.ToString()
Dim lineBreak As New LiteralControl("<br />")
PlaceHolder1.Controls.Add(hyper)
PlaceHolder1.Controls.Add(lineBreak)
--> myControlList.Add(hyper.ID)
ViewState("myControlList") = myControlList
End Sub
End Class
please help me out. Thanks.
A button click initiates a postback, and you only set myControlList to a thing if the request is not a post back, so it's nothing.
If you're wanting to create the list on page load, and then only keep adding to it with subsequent clicks, say, then you'll need to shove myControlList into the Session, or something, after creating it, then on button click retrieve it again, add to it, and re-set it in the Session.
To do this add and getting from the Session stuff, do,
Session("someDistinctKey") = myControlList;
myControlList = CType(Session("someDisctintKey"), List(Of String))
respectively.

Expanding an ASP.Net TreeView node from code-behind

I'm learning how to access the controls of an ASP.Net master page and trying to expand a particular TreeView node. I'm doing this from another page that is not a master page.
objContentPlaceHolder, objLoginView and objTreeView all have a value as confirmed by using the debugger.
Can you look at this code and let us know why the code in the for loop is not executing? It reaches the for loop but just skips over the for loop at that point.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objContentPlaceHolder As ContentPlaceHolder
Dim objLoginView As LoginView
Dim objTreeView As TreeView
objContentPlaceHolder = CType(Master.FindControl("ContentPlaceHolderBody"), ContentPlaceHolder)
If Not objContentPlaceHolder Is Nothing Then
objLoginView = CType(objContentPlaceHolder.FindControl("loginViewMain"), LoginView)
If Not objLoginView Is Nothing Then
objTreeView = CType(objLoginView.FindControl("TreeViewMain"), TreeView)
' Make sure all nodes for Maintenance are expanded.
'--------------------------------------------------
For Each treenode As TreeNode In objTreeView.Nodes
If treenode.Text = "Maintenance" Then
treenode.Expand()
End If
Next treenode
End If
End If
End Sub
* Update *
I changed the page load event handler to a PreRenderComplete event handler and would you believe it worked? Not sure why PreRender didn't but that was it. Thanks again everyone for all the help.
public Sub TreeView_TreeNodeDataBound(ByVal sender As Object, ByVal e As TreeNodeEventArgs )
dim mapNode as SiteMapNode = e.Node.DataItem as SiteMapNode
If mapNode.Title = "Maintenance" then
e.Node.Expand()
End if
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objContentPlaceHolder As ContentPlaceHolder
Dim objLoginView As LoginView
Dim objTreeView As TreeView
objContentPlaceHolder = CType(Master.FindControl("ContentPlaceHolderBody"), ContentPlaceHolder)
If Not objContentPlaceHolder Is Nothing Then
objLoginView = CType(objContentPlaceHolder.FindControl("loginViewMain"), LoginView)
If Not objLoginView Is Nothing Then
objTreeView = CType(objLoginView.FindControl("TreeViewMain"), TreeView)
objTreeView.TreeNodeDataBound += TreeView_TreeNodeDataBound
End If
End If
End Sub
Hope this will help
From your example, it looks like your logic is only checking the root nodes. When dealing with hierarchical data, you need to employ recursive logic to ensure that the entire structure gets evaluated.
Something like this is what you need:
Protected Sub btnSearch_Click(sender As Object, e As EventArgs)
For Each node As TreeNode In TreeView1.Nodes
ExpandNodeByValue("Maintenance", node)
Next
End Sub
Private Sub ExpandNodeByValue(value As String, parentNode As TreeNode)
For Each childNode As TreeNode In parentNode.ChildNodes
If childNode.Value.ToLower() = value.ToLower() Then
childNode.Expand()
End If
If childNode.ChildNodes.Count > 0 Then
ExpandNodeByValue(value, childNode)
End If
Next
End Sub
I would also suggest using a DirectCast instead of CType, at least temporarily, to ensure that the control is being found. You would implement that like this:
Dim objTreeView as TreeView = DirectCast(objLoginView.FindControl("TreeViewMain"), TreeView)
If objTreeView IsNot Nothing Then
'The control was found
End If

VB.net/Asp.net loading a control programatically with a public property to be set

I have a vb.net asp application where I'm loading a control (from another control on a page). I want to set a variable between the two controls when it loads.
This is where I load the control:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim AuditControl As Control = LoadControl("~/controls/auditcompanies.ascx")
phCompanies.Controls.Add(AuditControl)
End Sub
On the control that's being loaded i've exposed the item i want to change as a property
Public Property resultType() As String
Get
Return m_resultType
End Get
Set(ByVal value As String)
m_resultType = value
End Set
End Property
Basically all it is doing is setting a parameter for my table adaptor
Public Sub Load_Data()
dtblog = New dsDECorp.ClientInfoDataTable
dtblog = tablog.GetAudits(m_resultType)
For Each rClient As dsDECorp.ClientInfoRow In dtblog
CID = rClient.ClientID
ClientName = rClient.CompanyName
Next
dtblog.Dispose()
End Sub
How do I pass the parameter through the property from the first control to the second when it loads?
Thanks
Tom
I'm a C# guy so forgive me if I make any syntax errors but the following should work for you:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim AuditControl As Control = LoadControl("~/controls/auditcompanies.ascx")
Dim AuditControlType As Type = AuditControl.GetType()
Dim AuditField As FieldInfo = AuditControlType.GetField("resultType")
AuditField.SetValue(AuditControlType, "Your Value")
phCompanies.Controls.Add(AuditControl)
End Sub

Resources