Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 9th, 2009, 09:06 PM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Wrox Blog Question - LinkButton (Imar's Blog Engine Code)

Hi,


I am trying to integrate Wrox Blog engine code to a site that does NOT implement .NET role membership
features. The site has a user table with id, password, and role information. The userRole is
declared as tinyint in SQL2K database. The 2 roles are 1 or 0. Zero goes to anonymous users and
1 goes to admin who could update blogs. I updated the following original code as follows:


Original Code has the following line..:

BlogEntries.ascx CODE:

<asp:LinkButtonID="lnkEdit"runat="server"CommandName="Edit"Text="(Edit This Entry)"CssClass="EditLink"CommandArgument='<%#Eval("Id")%>'Visible='<%#CanEdit()%>'></asp:LinkButton></h2>

BlogEntries.ascx.vb CODE has the following...

Protected ReadOnly Property CanEdit() As Boolean
Get
Return Context.User.IsInRole("Administrator")
End Get
End Property

========================
Changed CODE:

But the following code does NOT turn on "Edit this Entry" link. What am I doing wrong?

BlogEntries.ascx
<asp:LinkButtonID="lnkEdit"runat="server"CommandName="Edit"Text="(Edit This Entry)"CssClass="blog_EditLink"CommandArgument=<%#Eval("Id")%> Visible='<%#isRole()%>'></asp:LinkButton></h2>

BlogEntries.ascx.vb

Public Property isRole() As Boolean
Get
If userRole = 1 Then
Return True
ElseIf userRole = 0 Then
Return False
End If
End Get
Set(ByVal value As Boolean)
ViewState("isRole") = value
End Set
End Property


Last edited by norman001; January 9th, 2009 at 09:16 PM..
 
Old January 10th, 2009, 05:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Where does userRole get its value?

The setter of your proeprty stores data in VIewStae, while the getter uses a private backing variable called userRole. Looks to me that userRole never gets a value..... Maybe this works:
Code:
 
Public Property isRole() As Boolean
  Get
    Dim temp As Integer
    If ViewState("IsRole") IsNot Nothing Then
      temp = Convert.ToInt32(ViewState("IsRole"))
    End If
    Return temp = 1
  End Get
  Set(ByVal value As Boolean)
    ViewState("isRole") = value
  End Set
End Property
I haven't tested this code, but I hope it shows you the general idea: the property now uses ViewState as the backing store in the setter and the getter...

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 11th, 2009, 12:02 AM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Wrox Blog Question - LinkButton (Imar's Blog Engine Code)

Thanks Imar! That code is perfect.!!
 
Old January 11th, 2009, 10:53 AM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Blog Edit/Save Error code 500

Hi Imar,

Every time I try to save a blog in blog edit/save form, I get the following error coming as pop-up window. Could I please ask how to debug this error. Thanks!

"Sys.WebForms.PageRequestManagerServerErrorExcepti on:An unknown error occurred while processing the request on the server. The status code returned from the server was:500"
 
Old January 11th, 2009, 10:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Trry removing the UpdatePanel and the ContentTemplate. That way, you get to see the real error...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 11th, 2009, 02:32 PM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Blog Edit/Save Error code 500

Hi, I found a solution in the web. I added the following line to web.config and the
error is gone now..

validateRequest="false"
 
Old January 11th, 2009, 04:22 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, yes, request validation..... Rather than setting it in web.config where it affects all the pages in your site, you could consider setting it in the page directive for the offending page only. Request validation is a security measure, and turning it off for the entire site makes your site a little less secure....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 12th, 2009, 12:21 AM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Blog Edit/Save Error code 500

Oops! Thank you. I removed that directive from web.config and added to the blogs main page. I have another question. In the bonus chapter content, under chapter 6, there is a word document that states implimenting 3 things with first one being the paging funtionality of blogs. The sample code for other things are there except the paging code. I am wondering whether paging code exist somewhere in the Wrox site. Thanks again for your prompt responses.. here is the text from the word doc..
...................................
1.Implement paging. The BlogEntries user control now displays all the blog entries that have been published within a certain category. If you blog a lot, this list may grow very long, making it hard to load and read the page. By using paging, where you show only, say, 20 records per page, things become a lot easier for the user.
.................................................. .......
 
Old January 12th, 2009, 02:56 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi norman001,

Take a look at page 294 and onwards. It exaplains how to implement paging with controls that do not support paging out of the box (like the DataList).

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 23rd, 2009, 08:23 PM
Registered User
 
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wrox Blog Paging

Hi Imar,

I was working on the paging for a while but it seems I am not getting anywhere. Once I run following code I get page numbers 1,2 next..but when I click them I don't see the data coming...could you please have a look at this code see what is wrong with it? The highlighted parts are added pagination code...

Thanks a bunch!

BlogEntries.ascx.vb:
=======================
Private Sub LoadData()
Dim myDataSet As DataSet = Nothing
'Dim myPageDataSource As New PagedDataSource()

If Request.QueryString.Get("startDate") IsNot Nothing Then
startDate = Convert.ToDateTime(Request.QueryString.Get("startDate"))
If Request.QueryString.Get("endDate") IsNot Nothing Then
endDate = Convert.ToDateTime(Request.QueryString.Get("endDate"))
Else
endDate = startDate
End If
startDatePass = startDate
endDatePass = endDate
Label1.Text = startDatePass
myDataSet = BlogManager.GetBlogEntries(startDate, endDate)
Process_Pagination(myDataSet)
If endDate = startDate Then
lblResults.Text = "Below you find blog entries posted on " & startDate.ToShortDateString() & "."
Else
lblResults.Text = "Below you find blog entries posted between " & startDate.ToShortDateString() & " and " & endDate.ToShortDateString() & "."
End If
Else
If Request.QueryString.Get("categoryId") IsNot Nothing Then
myDataSet = BlogManager.GetBlogEntries(Convert.ToInt32(Request .QueryString.Get("categoryId")))
Process_Pagination(myDataSet)
If myDataSet IsNot Nothing AndAlso myDataSet.Tables.Count > 0 AndAlso myDataSet.Tables(0).Rows.Count > 0 Then
lblResults.Text = "Below you find blog entries posted in the category " & myDataSet.Tables(0).Rows(0)("Description").ToString() & "."
BlogCategory = myDataSet.Tables(0).Rows(0)("Description").ToString()
End If
Else

If myDataSet IsNot Nothing AndAlso myDataSet.Tables.Count > 0 AndAlso myDataSet.Tables(0).Rows.Count > 0 Then
lblResults.Text = "Below you find the latest " & myDataSet.Tables(0).Rows.Count & " blog entries posted on the site."
End If
End If
End If

If myDataSet IsNot Nothing AndAlso myDataSet.Tables.Count > 0 AndAlso myDataSet.Tables(0).Rows.Count > 0 Then
dlBlogEntries.DataSource = myDataSet
dlBlogEntries.DataBind()
Process_Pagination(myDataSet)

Else
lblResults.Text = "No blog entries found for the date or category you requested."
End If
End Sub


‘ THE PAGINATION CODE WORKS…BUT PROBLEM IS HOW DO I GET NEXT & PREV PAGES to CONNECT TO THE DATA..

Protected Sub Process_Pagination(ByVal ds As DataSet)
Dim objPds As New PagedDataSource()
objPds.DataSource = ds.Tables(0).DefaultView
objPds.AllowPaging = True
Dim pagesize As Integer = 3
objPds.PageSize = pagesize
objPds.CurrentPageIndex = (PageNumber - 1)

If Not objPds.IsFirstPage Then
lnk_Prev.Visible = True
Else
lnk_Prev.Visible = False
End If

If Not objPds.IsLastPage Then
lnk_Next.Visible = True
Else
lnk_Next.Visible = False
End If

Dim arr As ArrayList = _process_pagination.Return_Pagination_Link(objPds. PageCount, 3, PageNumber)
If objPds.PageCount > 1 Then
rptPages.Visible = True
rptPages.DataSource = arr
rptPages.DataBind()
Else
rptPages.Visible = False
End If

dlBlogEntries.DataSource = objPds
dlBlogEntries.DataBind()
End Sub

Protected Sub rptPages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs )
Dim btnPage As LinkButton = CType(e.Item.FindControl("btnPage"), LinkButton)
PageNumber = CInt(btnPage.Text)
Dim myDataSet As DataSet = Nothing
dlBlogEntries.DataSource = myDataSet
dlBlogEntries.DataBind()
Process_Pagination(myDataSet)

End Sub

Protected Sub lnk_Next_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnk_Next.Click
PageNumber = PageNumber + 1
Dim myDataSet As DataSet = Nothing
dlBlogEntries.DataSource = myDataSet
dlBlogEntries.DataBind()
Process_Pagination(myDataSet)

End Sub

Protected Sub lnk_Prev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnk_Prev.Click
PageNumber = PageNumber - 1
Dim myDataSet As DataSet = Nothing
dlBlogEntries.DataSource = myDataSet
dlBlogEntries.DataBind()
Process_Pagination(myDataSet)

End Sub

Protected Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
AddHandler rptPages.ItemCommand, AddressOf Me.rptPages_ItemCommand
End Sub

Protected Sub rptPages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptPages.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim btnPage As LinkButton = CType(e.Item.FindControl("btnPage"), LinkButton)
If btnPage.Text = PageNumber Then
btnPage.CssClass = "pagination_link_selected"
Else
btnPage.CssClass = "pagination_link"
End If
End If
End Sub



BlogEntries.ascx
================
<div class="pagination_item">
<asp:LinkButton ID="lnk_Prev" runat="server" Text="Prev" CssClass="bold_link"></asp:LinkButton>&nbsp;
<asp:Repeater ID="rptPages" runat="server">
<ItemTemplate>
<asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument="<%# Container.DataItem %>"
Text='<%# Container.DataItem %>' runat="server"></asp:LinkButton>&nbsp;
</ItemTemplate>
</asp:Repeater>
&nbsp;
<asp:LinkButton ID="lnk_Next" runat="server" CssClass="bold_link" Text="Next"></asp:LinkButton>
</div>
================================================== =======================

Last edited by asphelp; January 23rd, 2009 at 11:24 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrox Blog in C# madAlan BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 22 June 12th, 2011 04:09 AM
Wrox Blog tblessed23 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 16 May 14th, 2007 04:08 PM
Wrox Blog: Viewing individual blog entries Tawanda BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 May 7th, 2007 12:06 PM
Login for Wrox Blog danielson BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 March 20th, 2007 02:12 PM
Wrox Blog Admin addstravel BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 23rd, 2006 05:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.