|
-
Oct 17th, 2004, 05:39 AM
#1
Thread Starter
Retired VBF Adm1nistrator
Re-Render ASP.NET <% %> Tags? [Resolved]
Righty. Bit of a tricky problem I've gotten myself into.
I've designed an application in such a manner, but I don't think ASP.NET will inherently let me do things this way.
I have a search page - search.aspx.
Now, there are about 10 different searches people can do. I cannot go into the specifics I'm afraid, but each of the searches are totally different requiring differently formatted results etc.
Each search type would also be pulling different data from the DB.
So. My idea was that the search.aspx page, depending on the search being performed, would pull a HTML template file from the drive (which contains <%# %> data tags), pop those into the repeater control and away we go. But alas, when I grab the HTML file from the drive and put it into the repeater, the ASP.Net tags are not evaluated - but instead sent straight as HTML.
So, if I look at the HTML source code of the page, its full of <% Container.DataItem(4) %> etc.
This is the search.aspx designed mode code:
VB Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="search.aspx.vb" Inherits="xxxxxxx.search" %>
<%= strOptionalStartCommentBlock %>
<%= strBodyHeader %>
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<%= strHeaderTemplate %>
</HeaderTemplate>
<ItemTemplate>
<%= strItemTemplate %>
</ItemTemplate>
<SeparatorTemplate>
<%= strSeparatorTemplate %>
</SeparatorTemplate>
<AlternatingItemTemplate>
<%= strAlternatingItemTemplate %>
</AlternatingItemTemplate>
<FooterTemplate>
<%= strFooterTemplate %>
</FooterTemplate>
</asp:Repeater>
<%= strBodyFooter %>
<%= strOptionalEndCommentBlock %>
<%= strOptionalGenerciBody %>
Then in search.aspx I have:
VB Code:
'' part of declarations:
''
Public strBodyHeader As String = vbNullString
Public strHeaderTemplate As String = vbNullString
Public strItemTemplate As String = vbNullString
Public strSeparatorTemplate As String = vbNullString
Public strAlternatingItemTemplate As String = vbNullString
Public strFooterTemplate As String = vbNullString
Public strBodyFooter As String = vbNullString
Public strOptionalStartCommentBlock As String = vbNullString
Public strOptionalEndCommentBlock As String = vbNullString
Public strOptionalGenerciBody As String = vbNullString
'' elsewhere:
''
strSQLStatement = "EXECUTE "
strBodyHeader = strFileContent(intQueryType).strBodyHead
strHeaderTemplate = strFileContent(intQueryType).strRepeaterHeader
strItemTemplate = strFileContent(intQueryType).strRepeaterItemTemplate
strAlternatingItemTemplate = strFileContent(intQueryType).strRepeaterAlternateItemTemplate
strSeparatorTemplate = strFileContent(intQueryType).strRepeaterSeperator
strFooterTemplate = strFileContent(intQueryType).strRepeaterFooter
strBodyFooter = strFileContent(intQueryType).strBodyFooter
Select Case intQueryType
Case 0
strSQLStatement &= "SQLFindX "
Case 1
strSQLStatement &= "SQLFindY "
Case 2
strSQLStatement &= "SQLFindZ "
Case 3
strSQLStatement &= "SQLFindA "
Case 4
strSQLStatement &= "SQLFindB "
Case 5
strSQLStatement &= "SQLFindC "
Case Else
GoTo sendGeneric
End Select
strSQLStatement &= intArea
If Not mySQLConnection.State = ConnectionState.Open Then mySQLConnection.Open()
mySQLCommand = New SqlCommand(strSQLStatement, mySQLConnection)
mySQLReader = mySQLCommand.ExecuteReader()
Repeater1.DataSource = mySQLReader
Repeater1.DataBind()
Here's a snippet from one of the HTML template pages:
(this would be stored in strFileContent(intQueryType))
Code:
<table width="100%" border="0" ID="Table5">
<tr>
<td class="fSmall" vAlign="top" align="left"><b>
Found <%# = strMatchesUpperBound %> Matches</b><br>
Displaying matches <%# = strMatchesLowerBound %> to <%# = strMatchesCurrentUpperBound %> below<br>
<table width="96%" border="0" ID="Table6">
<tr>
<td class="fsmall">Searching for<b>
<%# strSearchType %> </b> <%# = strLocation %></td>
<td class="fsmall" align="right">
<font color="#006699">More Search Options <b>»</b></font> </td>
</tr>
<tr>
So you see the ASP.NET Tags in there? When I test the page, the HTML is sent straight to my browser without being evaluated. So. Can I manually tell ASP.NET to re-evaluate a piece of text for ASP.NET server tags?
Or, is there an easier way to have a single asp.net page with different front-ends.
One idea I'm toying with is simply to have 10 different repeater controls on the page, each with their HTML filled in as usual.
Then, depending on the search being performed, I enable the required one, and databind that.
I think that might be easier in the long run....
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Oct 17th, 2004, 05:51 AM
#2
Thread Starter
Retired VBF Adm1nistrator
Bugger it. I'm going to go ahead and use 10 different repeaters.
What's the point in going to all this hassle for the exact same result?
So that's what I'm doing to do
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|