|
| URL Rewriting and Gridview Paging |
 |
Wed, 5 Mar 2008 02:58:42 +0000 |
Hello Everyone and thanks for your help in advance. I am writing a content
management system that utilizes url rewriting through a http handler. Each
article is loaded into a gridview control as the articles have multiple pages.
I used the gridview in order t utilize the native paging capabilities. For
example, the URL www.mysite.com/article/1.aspx is parsed to return an article ID
of 1 and a category of article. When the page loads initially, the first page
of the gridview works perfectly. I perform the parsing of the URL in the
Page_load sectioon of the control. However, when I click on one of the paging
links, I receive an error that seems to derive from the inability to retrieve
the article ID of 1 (the error message comes from a database call that states I
am trying to pass a string to a value of int). I should also mention the
gridview is housed within a user control that is dynamically loaded on the web
form. The logic worked perfectly well when I used the URL
Default.aspx?cp=Article&ID=1. I'm not sure where the problem lies. Any
help on this topic would be greatly appreciated.
|
| Post Reply
|
| Re: URL Rewriting and Gridview Paging |
 |
Wed, 5 Mar 2008 08:07:00 +0000 |
can you please share your code for better understanding..... your problem is
clouded now...
|
| Post Reply
|
| Re: URL Rewriting and Gridview Paging |
 |
Wed, 5 Mar 2008 10:16:15 +0000 |
I receive an error that seems to derive from the inability to retrieve the
article ID of 1 (the error message comes from a database call that states I am
trying to pass a string to a value of int).
I would suggest to solve this by debugging. It works, if your code works (as in:
we have a similar system working here). But you need to make sure that you get
your string parsing of the URL right, and you need to get your basics in.
The error indication (let me quote you: "the error message comes from a
database call that states I am trying to pass a string to a value of int")
means you are in the wrong forum here. I mean, this is not about handlers, url
rewwriting or something - it is about you passing a wrong value into a database
and the database blowing. More answers can not be provided, as you do not
provide the error, the value you pass in or any other information.
If I were you I would get the basics straight - then the error will disappear:
Debug the function. Put a breakpoint in, find out WHAT you pass into the
database. This is your first point. Knowing what goes wrong, so you can fix it.
Debug your code to pass the correct value in.
Each article is loaded into a gridview control as the articles have multiple
pages
This is most likely a TERRIBLY bad idea. You basically generate a TON Of
overhead. Gridvirews are not done for presenting content, the are too heavy. I
would suggest you only pull the data of a page into memory, or just pass this
data forward to a render method. The gridview totally goes out of the window. It
makes no sense, it is too slow, too heavy, not done for this.
The logic worked perfectly well when I used the URL
Default.aspx?cp=Article&ID=1. I'm not sure where the problem lies.
It most likely lies in the fact that the user control expects a specific URL
format and relies on it, while you decide not to use that format, so you and the
user control are justn ot using the same specification. There are two ways to
handle this:
Get the user control and you on the same spec, in that you basically make the
user control expect data in the form you provide.
Rewrite the URL on the way down so that the user control sees in the request the
"correct" formatting.
Which way you choose is or should be dependant on your architecture, which I
know nothing about, so I can not advice.
|
| Post Reply
|
| Re: URL Rewriting and Gridview Paging |
 |
Wed, 5 Mar 2008 14:43:37 +0000 |
First of all thanks for the response. As far as placing my post here, the
problem began when I placed and httphandler in place to perform URL remapping,
so I thought this might be a good starting point. YOur point about the user
control expecting a fromat that it is not being passed is obviously the case as
I have verified that the value being passed to the user control and thus the
stored procedure is not an integer, but a null string. Thus the error. In
regards to solutions, can you please elaborate a little more on another method
to display the articles, which may be the best solution. Each article is loaded
into a SQL database and consists of 5 or more data rows that need to be linked
together in some fashion. I considered the gridview since it had the native
paging capabilities built in. Otherwise, I would have to write some type of
custom rendering solution which I would think would amount to the same overhead.
Am I missing something?
I think my prevous explanation left a little to be desired. Here are some
details of what is going on. In the rewriting configuration file I have the
following:
<add
url="/Article/.*"
mappedUrl="~/Default.aspx" />
meaning any url with the word "Article" in it is remapped to the the
Default page of the site. The raw url is then parsed to look for something like
/Article/1.aspx. The parsing routine would return a value of 1, which would
then be passed to the data routine. This works fine on the original load of the
articles first page. However, when I click on one of the "next" links
automatically generated in the gridview, the error occurs because the url is not
received in the appropraite format. Not sure if I'm making sense the way I'm
explaining it, but hope I am.
|
| Post Reply
|
| Re: URL Rewriting and Gridview Paging |
 |
Wed, 5 Mar 2008 14:50:59 +0000 |
Each article is loaded into a SQL database and consists of 5 or more data rows
that need to be linked together in some fashion. I considered the gridview since
it had the native paging capabilities built in.
Well, the DataGRID is meant for showing tabular data. It does a lot except
paging, and that costs - it blows up your viewstate, and if you dont need 80% of
the functionality, just...
...sit down and write your own control. YOu will find it also to be able to be a
LOT faster.
I would have to write some type of custom rendering solution which I would think
would amount to the same overhead. Am I missing something?
You miss that you are doing a lot less than a gridview, and that in a lot more
specific scenario. I have a similar projet that we did some years ago, and that
comes back now (a new CMS), and I will jsut do my own control. That simple. No
need to analyze the URL in there - it is going to be used in a template only,
and there will be a TemplateContext that has all infos it needs (GUID of
article, page number - it is all parsed in a module further up, then redirected
to the proper url for the template, keeping the additional info in a context
object). Then I just sit down and do presentation - which in my case wil be a
lot heavier than in yours ,because I will not do the typical CMS
"mistake" of storing HTML in the database, so what I will have as
input is XML. Not XML as in "XHTML", but XML like in DocBook or
something similar we design, that has ZERO layout information in it.
However, when I click on one of the "next" links automatically
generated in the gridview, the error occurs because the url is not received in
the appropraite format. Not sure if I'm making sense the way I'm explaining it,
but hope I am.
Yes it is - the problem here in the core is that you are breaking ASP.NET
specifications. To be more exact, you are breaking GridView specifications. The
GridView is not meant to be used with URL formats like you have, so it does not
work. When you writea control like a grid, you have certain usages in mind, and
having every page on a separate base URL just is NOT what you are going for.
Plus, the GridView does obviously not handle the inversion of your URL mapping
well. Either you find a hook there (never used that control - I am fully
Infragistics here), or you just dont use it.
|
| Post Reply
|
|
|