HELP! How to generate HTML based on querystring

T

Tim Burkart

I'm sure this is simple. I'm writing from a classic ASP perspective which is
something I know well. I want to select/generate HTML on a page based on the
value of a querystring variable.

I tried this but got a runtime error:

<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim strVar, strURL as String
strVar = Request.Querystring("var")

select Case strVar
case "1"
strURL.text = "
src="http://someothersite.com/ProductSea...Linename&Ntx=mode+matchallpartial&N=0&BWS=0|2">"
case else
strURL.text = " src="http://someothersite.com""
end select

end sub
</script>

<td width="100%" align="left" valign="top">
<iframe name="othersite" width="99%" height="800" align="left"
scrolling="Auto" frameborder="0" hspace="10" vspace="10"
class="iframescroll" id="othersite"

<asp:label id="strURL" runat="server">
</iframe>

</td>

I appreciate if anyone can help me with this. I could always code the page
in classic asp or php but would like to do it in dotnet.

Thank you in advance!!

Tim
 
R

rowe_newsgroups

I'm sure this is simple. I'm writing from a classic ASP perspective which is
something I know well. I want to select/generate HTML on a page based on the
value of a querystring variable.

I tried this but got a runtime error:

<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim strVar, strURL as String
strVar = Request.Querystring("var")

select Case strVar
case "1"
strURL.text = "
src="http://someothersite.com/ProductSearch/QSResults.aspx?DPSV_Id=360640&...2">"
case else
strURL.text = " src="http://someothersite.com""
end select

end sub
</script>

<td width="100%" align="left" valign="top">
<iframe name="othersite" width="99%" height="800" align="left"
scrolling="Auto" frameborder="0" hspace="10" vspace="10"
class="iframescroll" id="othersite"

<asp:label id="strURL" runat="server">
</iframe>

</td>

I appreciate if anyone can help me with this. I could always code the page
in classic asp or php but would like to do it in dotnet.

Thank you in advance!!

Tim

Gosh that's ugly markup. You don't have an opening > for the iframe
element, you don't close the asp:Label element, and you have it all in
an orphaned <td> element. Before continuing you might want to consider
fixing the html before you work on the code.

Second, what was the runtime error? It's quite difficult to help you
if I don't know what the error was.

Thanks,

Seth Rowe
 
P

Patrice

For example it looks like to me you would need to double quotes when used
inside a literal string but as you said this is a runtime error this is
unlikely that ???

Please never post again about an error without telling what is the error
message you get.
 
T

Tim Burkart

I'm sorry if I offended anyone. I'm asking for help. Here is the error. The
error is coming from my web host so I don't have access to server settings.
I took a different approach, this time setting the entire iframe tag instead
of just the src attribute. The html for the iframe works fine.

<iframe name="othersite" width="99%" height="800" align="left"
scrolling="Auto" frameborder="0" hspace="10" vspace="10"
class="iframescroll" id="othersite"
src="http://someothersite.com/ProductSea...Linename&Ntx=mode+matchallpartial&N=0&BWS=0|2>"
</iframe>

Here is the new code -

<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim strVar, strIFRAME as String
strVar = "1"

select Case strVar
case "1"
strIFRAME.text = '<iframe name="othersite" width="99%" height="800"
align="left" scrolling="Auto" frameborder="0" hspace="10" vspace="10"
class="iframescroll" id="othersite"
"http://someothersite.com/ProductSea...Linename&Ntx=mode+matchallpartial&N=0&BWS=0|2"></iframe>'
case else
strIFRAME.text = '<iframe name="othersite" width="99%" height="800"
align="left" scrolling="Auto" frameborder="0" hspace="10" vspace="10"
class="iframescroll" id="othersite"
src="http://someothersite.com/ProductSea...Linename&Ntx=mode+matchallpartial&N=0&BWS=0|2"></iframe>'
end select

end sub
</script>

<td>
<asp:label id="strIFRAME" runat="server"/>
</td>

Server Error in '/' Application.
--------------------------------------------------------------------------------

Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors> tag within a "web.config"
configuration file located in the root directory of the current web
application. This <customErrors> tag should then have its "mode" attribute
set to "Off".


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirect" attribute of the application's
<customErrors> configuration tag to point to a custom error page URL.


<!-- Web.Config Configuration File -->

<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
 
R

rowe_newsgroups

I'm sorry if I offended anyone. I'm asking for help.

I don't think you offended anyone (or at least not me) - We just tend
to have a very stern way of correcting mistakes.

Instead of trying to correct your code, I'm going to try to just
rewrite it entirely. What exactly are you trying to do? Are you just
trying to set the source of an iframe dynamically based on a query
parameter? If so try this code:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>

<script runat="server">
Public Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
'// This assumes the variable in the query string is
called 'var'
'// i.e. Default.aspx?var=1
Dim s As String = Request.QueryString("var")
If s = "1" Then
framePlaceHolder.InnerHtml = "<iframe src=""http://
www.google.com""></iframe>"
Else
framePlaceHolder.InnerHtml = "<iframe src=""http://
www.yahoo.com""></iframe>"
End If
End Sub
</script>

</head>
<body>
<form id="form1" runat="server">
<div id="framePlaceHolder" runat="server">
</div>
</form>
</body>
</html>

Thanks,

Seth Rowe
 
T

Tim Burkart

Cool! It works!! So does everything become a form even if it's not a
traditional form?

Tim
 
R

rowe_newsgroups

Cool! It works!!

Great! Glad I helped.
So does everything become a form even if it's not a
traditional form?

Huh? I can't say I understand what you mean.

Basically, I added the runat="server" attribute to a div so I could
access it via server-side code. Then I handle the Page Load event and
check the value of the query parameter. Based on the value of the
parameter I insert the necessary html into my div - which in this case
was the iframe declaration.

Thanks,

Seth Rowe
 
P

Patrice

Not offended but the exact error message is really the first tool you should
use to debug a problem (you could test with the local build in server).

This time it looks like you are using a simple quotes which are not
supported in VB.NET. You have to use double quotes this way :
MyValue="src=""SomeAttribute"""

In both cases my guess is that you had compilation errors...
 
T

Tim Burkart

I would have never thought to wrap a form tag around the div tag when I
don't consider this to be a traditional HTML form... you know with input
fields (like a feedback form).
 
R

rowe_newsgroups

I would have never thought to wrap a form tag around the div tag when I
don't consider this to be a traditional HTML form... you know with input
fields (like a feedback form).

You won't wrap a form tag around every div element - as a matter of
fact you can only have one server-side form tag on the page. This tag
must contain any element you wish you access from your server side
code.

Thanks,

Seth Rowe
 
P

Patrice

Do you use Visual Web Developer ? It should really have caught such errors
when trying to run your application...

If not already you can use :
http://msdn2.microsoft.com/en-us/express/aa975050.aspx and select "Visual
Web Developer 2005 Express Edition" (which is free).

You'll have syntactic colooration and you'll be able to run your application
wiht the built-in test server (and as using locahost you'll be able to see
errors even perhaps at compile time in your case).
 
Top