Showing posts with label include. Show all posts
Showing posts with label include. Show all posts

Saturday, March 31, 2012

Server Side Include showing up in Screen Display

I am trying to include a subroutine in my aspx file, but when I do it shows up in the screen output. I have a sub and end sub as the first and last lines in the script, and I put the include statement near the top of the file. (See below)

<%@dotnet.itags.org. Page Language="VBScript" Debug="true" %>
<%@dotnet.itags.org. Import Namespace="System.IO" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<!--#include file="Get_Database_value.vbs"-->

<script runat="server">
Sub Page_Load
Response.Write ("Nothing")
End Sub
</script>

If I try to put the include inside the script directives it flags that as an error. I have read how includes could be used for headers and footers, but for that you put the includes inside the <html> </html> tags. I am coming from an asp background where I just included the file with vb code at the top of the asp page and it worked fine. I have read some things about the configuration file and how you can put compiled code in subdirectories, but right now I just want to get it to work.

Thanks for any help

Fred Rodriguez

Hi,

I believe it is not the right way to attached a script file. At ASP.NET you can put all your code/classes under App_Code folder in the root directory of your code. And normally classes in ASP.Net 2.0 uses .vb extension.

I suggest you change your Get_Database_value.vbs into a .net 2.0 format and put it under App_Code. If your using Visual Studio Express it's very easy to add App_Code folder.

Cheers...

server side include or user control?

I am setting up an asp.net site using the Ektron CMS. Every page in the
site uses the same basic template, with the look of the page changing
via CSS and an id on the body. The id is shared by all pages in a
subsection, e.g. everything in /about/ needs to have <body id="about">.
In the past what I've done is set a global variable in index.asp, then
include the template to render the page:
<%
pageid = "about"
defaultcontentid = 33
%>
<!--#include virtual="/include/mastertemplate.asp" -->
mastertemplate.asp would be the entire page, echoing and processing the
variables like so:
<!--#include virtual="/include/cmsfunctions.asp" -->
<body id="<%= pageid %>">
<%= cmsRenderContent(defaultcontentid) %>
This worked great. I needed one index.asp for each subsection, and had
no duplication of template code. If the template needed to be updated, I
just gave it to the designer, who modified it in Dreamweaver or
whatever. The separation between presentation and logic was good, and
any code that generated html was in an easily-modified function.
I've experimented with a similar approach in asp.net, and have the start
of it working, but the additional complication is that
mastertemplate.aspx has some codebehind related to the cms server
controls that it uses, and I need to use the passed-in variables within
that codebehind. For example, I'd establish a default content id in the
calling page, and if the mastertemplate.asp doesn't detect an id in the
url, it will use the default.
I am looking for examples of this approach in asp.net but I keep running
across advice to use user controls instead. But it seems like user
controls are used for parts of pages, not the page template itself. Is
that right? Can a user control contain server controls? How would I pass
variables from a "stub" calling page to the user control page? Can a
user control be modified in something like Dreamweaver?
Thanks,
markgenerally they are right.
You will typically put a "place holder" into the template and then replace
that "place holder" with content created from a control (.ascx file). the
content is injected into the position of the "place holder" by using the
page.loadcontrol method.
example:
--
...somewhere in your code
' Dynamically inject a signin login module into the page
'---
If Request.IsAuthenticated = False Then
LoginControl.Controls.Add(Page.LoadControl("~/SignIn.ascx"))
End If
... somewhere in your template
<asp:placeholder id="LoginControl" runat="server" />
"Mark" <mark12b@.yahoo.com> wrote in message
news:mark12b-F29D08.12133710052005@.news.isp.giganews.com...
>I am setting up an asp.net site using the Ektron CMS. Every page in the
> site uses the same basic template, with the look of the page changing
> via CSS and an id on the body. The id is shared by all pages in a
> subsection, e.g. everything in /about/ needs to have <body id="about">.
> In the past what I've done is set a global variable in index.asp, then
> include the template to render the page:
> <%
> pageid = "about"
> defaultcontentid = 33
> %>
> <!--#include virtual="/include/mastertemplate.asp" -->
> mastertemplate.asp would be the entire page, echoing and processing the
> variables like so:
> <!--#include virtual="/include/cmsfunctions.asp" -->
> <body id="<%= pageid %>">
> <%= cmsRenderContent(defaultcontentid) %>
> This worked great. I needed one index.asp for each subsection, and had
> no duplication of template code. If the template needed to be updated, I
> just gave it to the designer, who modified it in Dreamweaver or
> whatever. The separation between presentation and logic was good, and
> any code that generated html was in an easily-modified function.
> I've experimented with a similar approach in asp.net, and have the start
> of it working, but the additional complication is that
> mastertemplate.aspx has some codebehind related to the cms server
> controls that it uses, and I need to use the passed-in variables within
> that codebehind. For example, I'd establish a default content id in the
> calling page, and if the mastertemplate.asp doesn't detect an id in the
> url, it will use the default.
> I am looking for examples of this approach in asp.net but I keep running
> across advice to use user controls instead. But it seems like user
> controls are used for parts of pages, not the page template itself. Is
> that right? Can a user control contain server controls? How would I pass
> variables from a "stub" calling page to the user control page? Can a
> user control be modified in something like Dreamweaver?
> Thanks,
> --
> mark
Include files are old fashioned.
User controls are a better approach. Yes, they can contain any kind of
controls you'd like. You can create public properties, methods, and events
to facilitate communication between the user control and the page.
I agree with you that user controls do not fully achieve the "template"
functionality you s as gracefully as we'd all like, but the only great
solution is in ASP.NET 2.0 (due out later this year) which implements
"Master Pages".
Here's more info:
http://SteveOrr.net/faq/usercustom.aspx
http://www.c-sharpcorner.com/Code/2...MasterPages.asp
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Mark" <mark12b@.yahoo.com> wrote in message
news:mark12b-F29D08.12133710052005@.news.isp.giganews.com...
>I am setting up an asp.net site using the Ektron CMS. Every page in the
> site uses the same basic template, with the look of the page changing
> via CSS and an id on the body. The id is shared by all pages in a
> subsection, e.g. everything in /about/ needs to have <body id="about">.
> In the past what I've done is set a global variable in index.asp, then
> include the template to render the page:
> <%
> pageid = "about"
> defaultcontentid = 33
> %>
> <!--#include virtual="/include/mastertemplate.asp" -->
> mastertemplate.asp would be the entire page, echoing and processing the
> variables like so:
> <!--#include virtual="/include/cmsfunctions.asp" -->
> <body id="<%= pageid %>">
> <%= cmsRenderContent(defaultcontentid) %>
> This worked great. I needed one index.asp for each subsection, and had
> no duplication of template code. If the template needed to be updated, I
> just gave it to the designer, who modified it in Dreamweaver or
> whatever. The separation between presentation and logic was good, and
> any code that generated html was in an easily-modified function.
> I've experimented with a similar approach in asp.net, and have the start
> of it working, but the additional complication is that
> mastertemplate.aspx has some codebehind related to the cms server
> controls that it uses, and I need to use the passed-in variables within
> that codebehind. For example, I'd establish a default content id in the
> calling page, and if the mastertemplate.asp doesn't detect an id in the
> url, it will use the default.
> I am looking for examples of this approach in asp.net but I keep running
> across advice to use user controls instead. But it seems like user
> controls are used for parts of pages, not the page template itself. Is
> that right? Can a user control contain server controls? How would I pass
> variables from a "stub" calling page to the user control page? Can a
> user control be modified in something like Dreamweaver?
> Thanks,
> --
> mark
In article <#3rMAzZVFHA.3696@.TK2MSFTNGP10.phx.gbl>,
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote:

> I agree with you that user controls do not fully achieve the "template"
> functionality you s as gracefully as we'd all like, but the only great
> solution is in ASP.NET 2.0 (due out later this year) which implements
> "Master Pages".
> Here's more info:
> http://SteveOrr.net/faq/usercustom.aspx
> http://www.c-sharpcorner.com/Code/2...MasterPages.asp
Yes, Master Pages is most like what I was after. Now I am thinking about
just passing the section name in the url and have everything run through
a single page. Instead of
/about/index.aspx?id=123
/portfolio/index.aspx?id=456
I'll go
/index.aspx?s=about&id=123
/index.aspx?s=portfolio&id=456
This should work fine, especially since the cms has url aliasing.
Thnkas,
Yes, I've tried that approach before and it's not as easy as it might seem
at first.
Since everything is essentially a postback to the same page, this opens up
new hassles related to dynamically creating controls at runtime and managing
them all between postbacks and keeping them from conflicting with eachother
in various ways.
If you can, skip to ASP.NET 2.0 and use master pages. Otherwise I'd suggest
you use multiple pages with header and/or footer controls to help manage a
common look & feel.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Mark" <mark12b@.yahoo.com> wrote in message
news:mark12b-377F1D.14180810052005@.news.isp.giganews.com...
> In article <#3rMAzZVFHA.3696@.TK2MSFTNGP10.phx.gbl>,
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote:
>
> Yes, Master Pages is most like what I was after. Now I am thinking about
> just passing the section name in the url and have everything run through
> a single page. Instead of
> /about/index.aspx?id=123
> /portfolio/index.aspx?id=456
> I'll go
> /index.aspx?s=about&id=123
> /index.aspx?s=portfolio&id=456
> This should work fine, especially since the cms has url aliasing.
> Thnkas,

server side include or user control?

I am setting up an asp.net site using the Ektron CMS. Every page in the
site uses the same basic template, with the look of the page changing
via CSS and an id on the body. The id is shared by all pages in a
subsection, e.g. everything in /about/ needs to have <body id="about">.

In the past what I've done is set a global variable in index.asp, then
include the template to render the page:

<%
pageid = "about"
defaultcontentid = 33
%>
<!--#include virtual="/include/mastertemplate.asp" --
mastertemplate.asp would be the entire page, echoing and processing the
variables like so:

<!--#include virtual="/include/cmsfunctions.asp" -->
<body id="<%= pageid %>">
<%= cmsRenderContent(defaultcontentid) %
This worked great. I needed one index.asp for each subsection, and had
no duplication of template code. If the template needed to be updated, I
just gave it to the designer, who modified it in Dreamweaver or
whatever. The separation between presentation and logic was good, and
any code that generated html was in an easily-modified function.

I've experimented with a similar approach in asp.net, and have the start
of it working, but the additional complication is that
mastertemplate.aspx has some codebehind related to the cms server
controls that it uses, and I need to use the passed-in variables within
that codebehind. For example, I'd establish a default content id in the
calling page, and if the mastertemplate.asp doesn't detect an id in the
url, it will use the default.

I am looking for examples of this approach in asp.net but I keep running
across advice to use user controls instead. But it seems like user
controls are used for parts of pages, not the page template itself. Is
that right? Can a user control contain server controls? How would I pass
variables from a "stub" calling page to the user control page? Can a
user control be modified in something like Dreamweaver?

Thanks,

--
markgenerally they are right.

You will typically put a "place holder" into the template and then replace
that "place holder" with content created from a control (.ascx file). the
content is injected into the position of the "place holder" by using the
page.loadcontrol method.

example:
--------
...somewhere in your code

' Dynamically inject a signin login module into the page
'---------------------
If Request.IsAuthenticated = False Then
LoginControl.Controls.Add(Page.LoadControl("~/SignIn.ascx"))
End If

.... somewhere in your template

<asp:placeholder id="LoginControl" runat="server" /
"Mark" <mark12b@.yahoo.com> wrote in message
news:mark12b-F29D08.12133710052005@.news.isp.giganews.com...
>I am setting up an asp.net site using the Ektron CMS. Every page in the
> site uses the same basic template, with the look of the page changing
> via CSS and an id on the body. The id is shared by all pages in a
> subsection, e.g. everything in /about/ needs to have <body id="about">.
> In the past what I've done is set a global variable in index.asp, then
> include the template to render the page:
> <%
> pageid = "about"
> defaultcontentid = 33
> %>
> <!--#include virtual="/include/mastertemplate.asp" -->
> mastertemplate.asp would be the entire page, echoing and processing the
> variables like so:
> <!--#include virtual="/include/cmsfunctions.asp" -->
> <body id="<%= pageid %>">
> <%= cmsRenderContent(defaultcontentid) %>
> This worked great. I needed one index.asp for each subsection, and had
> no duplication of template code. If the template needed to be updated, I
> just gave it to the designer, who modified it in Dreamweaver or
> whatever. The separation between presentation and logic was good, and
> any code that generated html was in an easily-modified function.
> I've experimented with a similar approach in asp.net, and have the start
> of it working, but the additional complication is that
> mastertemplate.aspx has some codebehind related to the cms server
> controls that it uses, and I need to use the passed-in variables within
> that codebehind. For example, I'd establish a default content id in the
> calling page, and if the mastertemplate.asp doesn't detect an id in the
> url, it will use the default.
> I am looking for examples of this approach in asp.net but I keep running
> across advice to use user controls instead. But it seems like user
> controls are used for parts of pages, not the page template itself. Is
> that right? Can a user control contain server controls? How would I pass
> variables from a "stub" calling page to the user control page? Can a
> user control be modified in something like Dreamweaver?
> Thanks,
> --
> mark
Include files are old fashioned.
User controls are a better approach. Yes, they can contain any kind of
controls you'd like. You can create public properties, methods, and events
to facilitate communication between the user control and the page.
I agree with you that user controls do not fully achieve the "template"
functionality you seek as gracefully as we'd all like, but the only great
solution is in ASP.NET 2.0 (due out later this year) which implements
"Master Pages".

Here's more info:
http://SteveOrr.net/faq/usercustom.aspx
http://www.c-sharpcorner.com/Code/2...MasterPages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Mark" <mark12b@.yahoo.com> wrote in message
news:mark12b-F29D08.12133710052005@.news.isp.giganews.com...
>I am setting up an asp.net site using the Ektron CMS. Every page in the
> site uses the same basic template, with the look of the page changing
> via CSS and an id on the body. The id is shared by all pages in a
> subsection, e.g. everything in /about/ needs to have <body id="about">.
> In the past what I've done is set a global variable in index.asp, then
> include the template to render the page:
> <%
> pageid = "about"
> defaultcontentid = 33
> %>
> <!--#include virtual="/include/mastertemplate.asp" -->
> mastertemplate.asp would be the entire page, echoing and processing the
> variables like so:
> <!--#include virtual="/include/cmsfunctions.asp" -->
> <body id="<%= pageid %>">
> <%= cmsRenderContent(defaultcontentid) %>
> This worked great. I needed one index.asp for each subsection, and had
> no duplication of template code. If the template needed to be updated, I
> just gave it to the designer, who modified it in Dreamweaver or
> whatever. The separation between presentation and logic was good, and
> any code that generated html was in an easily-modified function.
> I've experimented with a similar approach in asp.net, and have the start
> of it working, but the additional complication is that
> mastertemplate.aspx has some codebehind related to the cms server
> controls that it uses, and I need to use the passed-in variables within
> that codebehind. For example, I'd establish a default content id in the
> calling page, and if the mastertemplate.asp doesn't detect an id in the
> url, it will use the default.
> I am looking for examples of this approach in asp.net but I keep running
> across advice to use user controls instead. But it seems like user
> controls are used for parts of pages, not the page template itself. Is
> that right? Can a user control contain server controls? How would I pass
> variables from a "stub" calling page to the user control page? Can a
> user control be modified in something like Dreamweaver?
> Thanks,
> --
> mark
In article <#3rMAzZVFHA.3696@.TK2MSFTNGP10.phx.gbl>,
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote:

> I agree with you that user controls do not fully achieve the "template"
> functionality you seek as gracefully as we'd all like, but the only great
> solution is in ASP.NET 2.0 (due out later this year) which implements
> "Master Pages".
> Here's more info:
> http://SteveOrr.net/faq/usercustom.aspx
> http://www.c-sharpcorner.com/Code/2...MasterPages.asp

Yes, Master Pages is most like what I was after. Now I am thinking about
just passing the section name in the url and have everything run through
a single page. Instead of

/about/index.aspx?id=123
/portfolio/index.aspx?id=456

I'll go

/index.aspx?s=about&id=123
/index.aspx?s=portfolio&id=456

This should work fine, especially since the cms has url aliasing.

Thnkas,
Yes, I've tried that approach before and it's not as easy as it might seem
at first.
Since everything is essentially a postback to the same page, this opens up
new hassles related to dynamically creating controls at runtime and managing
them all between postbacks and keeping them from conflicting with eachother
in various ways.
If you can, skip to ASP.NET 2.0 and use master pages. Otherwise I'd suggest
you use multiple pages with header and/or footer controls to help manage a
common look & feel.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Mark" <mark12b@.yahoo.com> wrote in message
news:mark12b-377F1D.14180810052005@.news.isp.giganews.com...
> In article <#3rMAzZVFHA.3696@.TK2MSFTNGP10.phx.gbl>,
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote:
>> I agree with you that user controls do not fully achieve the "template"
>> functionality you seek as gracefully as we'd all like, but the only great
>> solution is in ASP.NET 2.0 (due out later this year) which implements
>> "Master Pages".
>>
>> Here's more info:
>> http://SteveOrr.net/faq/usercustom.aspx
>> http://www.c-sharpcorner.com/Code/2...MasterPages.asp
> Yes, Master Pages is most like what I was after. Now I am thinking about
> just passing the section name in the url and have everything run through
> a single page. Instead of
> /about/index.aspx?id=123
> /portfolio/index.aspx?id=456
> I'll go
> /index.aspx?s=about&id=123
> /index.aspx?s=portfolio&id=456
> This should work fine, especially since the cms has url aliasing.
> Thnkas,

Saturday, March 24, 2012

Server.Execute

Hiyo

I want to perform a programmatic server-side include, and I think that the
best way would be to use Server.Execute(path, optional textwriter).
Certainly ommitting the textwriter means that I can write to the output of
my page.

...however...

The content I wanted to append to the page is aspx code stored in a database
(surely this isn't the best way - suggestions welcome please!), and so I
figure it would be faster to write the code from the database into the aspx
output like this:

<html><body>test starts<br
string dbaspx = Database.ReadSomeField();
// dbaspx == "<aspx:-- some aspx code --/>"
Server.Execute(dbaspx);

<br>test stops</body></html
Kinda an odd scenario; your thoughts welcome :) Thanks in advance,
BenBen hi,

if you keep the data in DB its probebly static so maybe its betteer to
store the data in application cache.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Where is Server.Execute in .NET?

"Natty Gur" <natty@.dao2com.com> wrote in message
news:O00n72KbDHA.2672@.tk2msftngp13.phx.gbl...
> Ben hi,
> if you keep the data in DB its probebly static so maybe its betteer to
> store the data in application cache.
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
It's a method of the HttpServerUtility class. Similar to Server.Transfer,
except that after executing the target page, control returns to the calling
page. It was more in vogue with classic ASP, since classic ASP is
procedural. You could use it to do a "dynamic include" - include content
from another ASP page conditionally. ASP.Net has better mechanisms for such
things, so it isn't used very often.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"MS News (MS ILM)" <sql_agentmans@.hotmail.com> wrote in message
news:%23DlzaXMbDHA.3768@.tk2msftngp13.phx.gbl...
> Where is Server.Execute in .NET?
>
> "Natty Gur" <natty@.dao2com.com> wrote in message
> news:O00n72KbDHA.2672@.tk2msftngp13.phx.gbl...
> > Ben hi,
> > if you keep the data in DB its probebly static so maybe its betteer to
> > store the data in application cache.
> > Natty Gur, CTO
> > Dao2Com Ltd.
> > 34th Elkalay st. Raanana
> > Israel , 43000
> > Phone Numbers:
> > Office: +972-(0)9-7740261
> > Fax: +972-(0)9-7740261
> > Mobile: +972-(0)58-888377
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!

Thursday, March 22, 2012

Server.Execute vs Include?

I have several small pieces of common code that get applied to each page.
Which is better a better way of including them in other pages? Use the
traditional include statement or go with the Server.Execute("pagename")
method.

Thanks
KeithNeither, unless the code absolutely has to be in a "webform"

Instead, just create a module or class and call the code like you would any
other function.

"Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> I have several small pieces of common code that get applied to each page.
> Which is better a better way of including them in other pages? Use the
> traditional include statement or go with the Server.Execute("pagename")
> method.
> Thanks
> Keith
That seems rather silly to create a class simply to write out 4 or 5 lines
of HTML with reponse.write. Not to mention maintaining all the dam double
quotes within the reponse.write text. All my HTML conforms to the standards
required for MSXML and XSL/XSLT. Placing everything in an object for the
sake of making an object makes it much more dificult to debug. OOP is a
wonderfull thing but only when applied where appropriate.

I think I will stick with include files for things of this nature. The
server.execute is fine but objects defined by the parent are not available
to the child whereas in an include they are.

Keith

PS: The microsoft guy told me to stay away from modules!

"Boban Dragojlovic" <news@._N_O_S_P_AM_dragojlovic.org> wrote in message
news:lduqb.847$A71.375@.newssvr14.news.prodigy.com. ..
> Neither, unless the code absolutely has to be in a "webform"
> Instead, just create a module or class and call the code like you would
any
> other function.
>
> "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> > I have several small pieces of common code that get applied to each
page.
> > Which is better a better way of including them in other pages? Use the
> > traditional include statement or go with the Server.Execute("pagename")
> > method.
> > Thanks
> > Keith
I think the easiest way is to throw the HTML and other stuff into User
Controls. Then you just drop the user controls onto your web page for them
to appear. These are similiar to includes but better.

Jeff

"Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
news:%23adm3qJpDHA.1676@.TK2MSFTNGP09.phx.gbl...
> That seems rather silly to create a class simply to write out 4 or 5 lines
> of HTML with reponse.write. Not to mention maintaining all the dam double
> quotes within the reponse.write text. All my HTML conforms to the
standards
> required for MSXML and XSL/XSLT. Placing everything in an object for the
> sake of making an object makes it much more dificult to debug. OOP is a
> wonderfull thing but only when applied where appropriate.
> I think I will stick with include files for things of this nature. The
> server.execute is fine but objects defined by the parent are not available
> to the child whereas in an include they are.
> Keith
> PS: The microsoft guy told me to stay away from modules!
>
> "Boban Dragojlovic" <news@._N_O_S_P_AM_dragojlovic.org> wrote in message
> news:lduqb.847$A71.375@.newssvr14.news.prodigy.com. ..
> > Neither, unless the code absolutely has to be in a "webform"
> > Instead, just create a module or class and call the code like you would
> any
> > other function.
> > "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> > news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> > > I have several small pieces of common code that get applied to each
> page.
> > > Which is better a better way of including them in other pages? Use
the
> > > traditional include statement or go with the
Server.Execute("pagename")
> > > method.
> > > > Thanks
> > > Keith
> >
Now that sounds like a more reasonable solution to me as well.

Cheers
Keith

"Jeff" <jsiver@.dls.net> wrote in message
news:O7bV3ycpDHA.3688@.TK2MSFTNGP11.phx.gbl...
> I think the easiest way is to throw the HTML and other stuff into User
> Controls. Then you just drop the user controls onto your web page for
them
> to appear. These are similiar to includes but better.
> Jeff
> "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> news:%23adm3qJpDHA.1676@.TK2MSFTNGP09.phx.gbl...
> > That seems rather silly to create a class simply to write out 4 or 5
lines
> > of HTML with reponse.write. Not to mention maintaining all the dam
double
> > quotes within the reponse.write text. All my HTML conforms to the
> standards
> > required for MSXML and XSL/XSLT. Placing everything in an object for the
> > sake of making an object makes it much more dificult to debug. OOP is a
> > wonderfull thing but only when applied where appropriate.
> > I think I will stick with include files for things of this nature. The
> > server.execute is fine but objects defined by the parent are not
available
> > to the child whereas in an include they are.
> > Keith
> > PS: The microsoft guy told me to stay away from modules!
> > "Boban Dragojlovic" <news@._N_O_S_P_AM_dragojlovic.org> wrote in message
> > news:lduqb.847$A71.375@.newssvr14.news.prodigy.com. ..
> > > Neither, unless the code absolutely has to be in a "webform"
> > > > Instead, just create a module or class and call the code like you
would
> > any
> > > other function.
> > > > > "Keith Chadwick" <kchadwick@.leewardsystems.com> wrote in message
> > > news:uRseM1HpDHA.1960@.TK2MSFTNGP12.phx.gbl...
> > > > I have several small pieces of common code that get applied to each
> > page.
> > > > Which is better a better way of including them in other pages? Use
> the
> > > > traditional include statement or go with the
> Server.Execute("pagename")
> > > > method.
> > > > > > Thanks
> > > > Keith
> > > > > >

Server.HtmlEncode fails with "Server is undefined"

In my application I need to allow users to cut 'n' paste stuff from
various sources, some of which might include dodgy characters such as
"<". Natch, IE interprets these as potentially dangerous and provides
a mechanism to encode/decode them. However I can't seem to get it to
work:
...
<asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px;
POSITION: absolute; TOP: 124px" tabIndex=29 runat="server"
onblur="return ReplaceScriptCode()" Width="553px" Height="52px"
CssClass="STANDARD" Font-Names="Arial" Font-Size="8pt"
TextMode="MultiLine"></asp:textbox>
...
<script language="vb" runat=server>
Public Sub ReplaceScriptCode()
txtDescription.Text = Server.HtmlEncode(txtDescription.Text)
End Sub
</script>
The app. barfs, telling me that "Server is undefined". Thoughts?
Thanks
Edwardteddysnips@.hotmail.com wrote:
> In my application I need to allow users to cut 'n' paste stuff from
> various sources, some of which might include dodgy characters such as
> "<". Natch, IE interprets these as potentially dangerous and provides
> a mechanism to encode/decode them. However I can't seem to get it to
> work:
> ...
> <asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px;
> POSITION: absolute; TOP: 124px" tabIndex=29 runat="server"
> onblur="return ReplaceScriptCode()" Width="553px" Height="52px"
> CssClass="STANDARD" Font-Names="Arial" Font-Size="8pt"
> TextMode="MultiLine"></asp:textbox>
> ...
> <script language="vb" runat=server>
> Public Sub ReplaceScriptCode()
> txtDescription.Text = Server.HtmlEncode(txtDescription.Text)
> End Sub
> </script>
> The app. barfs, telling me that "Server is undefined". Thoughts?
> Thanks
> Edward
>
You are mixing server code and client code. The code in the onblur event
doesn't call the VB subroutine that you have put in the server code, it
calls the client side function with the same name.
As you don't get the error message that ReplaceScriptCode is undefined,
I assume that you also have a Javascript or VBScript function with that
name?
If you have put the same code in that function as in your VB server side
subroutine, that will obviously not work, as there is no Server object
on the client side.
What is it that you are trying to do, really? There is nothing dangerous
about pasting markup code into a textbox. ASP.NET won't let you post
stuff that contains markup code to the server by default, but that is a
completely different thing, and has a completely different solution.
Gran Andersson
_____
http://www.guffa.com
Edward
I think your problem is that the OnBlur event, which is calling your
ReplaceScriptCode is a client side event, whereas the Server object is serve
r
side. The code works fine if executed from from code behind:
<asp:TextBox ID="txtDescription" Style="z-index: 102; left:
111px; position: absolute;
top: 124px" TabIndex="29" runat="server" onblur="return
ReplaceScriptCode()"
Width="553px" Height="52px" CssClass="STANDARD"
Font-Names="Arial" Font-Size="8pt"
TextMode="MultiLine"></asp:TextBox>
<script language="vb" runat="server">
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
txtDescription.Text =
Server.HtmlEncode(txtDescription.Text)
End Sub
</script>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
Just hit the button to test it.
Hope this helps
Tom
"teddysnips@.hotmail.com" wrote:

> In my application I need to allow users to cut 'n' paste stuff from
> various sources, some of which might include dodgy characters such as
> "<". Natch, IE interprets these as potentially dangerous and provides
> a mechanism to encode/decode them. However I can't seem to get it to
> work:
> ...
> <asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px;
> POSITION: absolute; TOP: 124px" tabIndex=29 runat="server"
> onblur="return ReplaceScriptCode()" Width="553px" Height="52px"
> CssClass="STANDARD" Font-Names="Arial" Font-Size="8pt"
> TextMode="MultiLine"></asp:textbox>
> ...
> <script language="vb" runat=server>
> Public Sub ReplaceScriptCode()
> txtDescription.Text = Server.HtmlEncode(txtDescription.Text)
> End Sub
> </script>
> The app. barfs, telling me that "Server is undefined". Thoughts?
> Thanks
> Edward
>
On 4 Jul, 12:09, G=F6ran Andersson <g...@.guffa.com> wrote:
> teddysn...@.hotmail.com wrote:
[=2E..]
> What is it that you are trying to do, really? There is nothing dangerous
> about pasting markup code into a textbox. ASP.NET won't let you post
> stuff that contains markup code to the server by default, but that is a
> completely different thing, and has a completely different solution.
As you say. The problem comes when the user tries to post the text
(dumb of me, I know, I should have mentioned that).
The user wants to be able to paste stuff into text boxes which is then
sent to the server for processing (generally, storage in a database
and later retrieval).
I don't want to remove validation at page level - in fact I doubt the
clients would let me. I rolled my own client-side jscript to strip
out markup code which was called from the OnBlur event, but I thought
I could improve on it using built-in functions.
In short, the requirement is:
ASP.NET with VB code behind.
User pastes stuff into an ASP TextBox
Presses "Save" button. Save button is asp:Button running server-side.
Remove/replace "dangerous" code with HtmlEncoded stuff and save to
database.
Thoughts?
Thanks,
Edward
teddysnips@.hotmail.com wrote:
> On 4 Jul, 12:09, Gran Andersson <g...@.guffa.com> wrote:
> [...]
> As you say. The problem comes when the user tries to post the text
> (dumb of me, I know, I should have mentioned that).
> The user wants to be able to paste stuff into text boxes which is then
> sent to the server for processing (generally, storage in a database
> and later retrieval).
> I don't want to remove validation at page level - in fact I doubt the
> clients would let me.
That validation is not required, as long as you make sure that you treat
the data as unvalidated on the server side. That means that you never
put it on a page or use it in a database query without making sure that
it's properly encoded.
As the validation doesn't cover any possible circumstances, that's what
you already should be doing anyway.
Read up on cross site scripting and sql injections, so that you know how
these types of security leaks can be exploited.

> I rolled my own client-side jscript to strip
> out markup code which was called from the OnBlur event, but I thought
> I could improve on it using built-in functions.
> In short, the requirement is:
> ASP.NET with VB code behind.
> User pastes stuff into an ASP TextBox
> Presses "Save" button. Save button is asp:Button running server-side.
> Remove/replace "dangerous" code with HtmlEncoded stuff and save to
> database.
> Thoughts?
Storing it html encoded in the database served no purpose. Html code can
not harm the database. You just have to make sure it isn't put on a page
without being encoded.
Gran Andersson
_____
http://www.guffa.com
On 4 Jul, 15:58, G=F6ran Andersson <g...@.guffa.com> wrote:
> teddysn...@.hotmail.com wrote:
us
[=2E..]
Thanks for all your help so far - it really is appreciated.
I reaslise that there's no danger to the database from the text, or
markup code (actually, in the scenario at present, it's simply users
copying and pasting e-mail messages wholesale, including the reply
prefixes e.g. >> as seen above which are the main problem). I just
want to allow the users to copy and paste what they want and save this
text to the database without incurring "A potentially dangerous
Request.Form value ... " error. So it seems to make sense to htlm-
encode the text, whatever it is, save it, and then un-html-encode it
when the data is retrieved and displayed.
I can't be the only person in history to have encountered this problem
yet I can't seem to find any examples that satisfy my requirements. I
thought this page:
http://www.asp.net/faq/RequestValidation.aspx#5
had it, but I can't make it work.
Any further ideas before you lose patience completely?
Edward
<teddysnips@.hotmail.com> wrote in message
news:1183563744.577845.215450@.m36g2000hse.googlegroups.com...

> Any further ideas before you lose patience completely?
Would something like this solve your problem:?
http://scriptasylum.com/tutorials/e...ode-decode.html
Mark Rae
ASP.NET MVP
http://www.markrae.net
teddysnips@.hotmail.com wrote:
> On 4 Jul, 15:58, Gran Andersson <g...@.guffa.com> wrote:
> [...]
> Thanks for all your help so far - it really is appreciated.
> I reaslise that there's no danger to the database from the text, or
> markup code (actually, in the scenario at present, it's simply users
> copying and pasting e-mail messages wholesale, including the reply
> prefixes e.g. >> as seen above which are the main problem). I just
> want to allow the users to copy and paste what they want and save this
> text to the database without incurring "A potentially dangerous
> Request.Form value ... " error. So it seems to make sense to htlm-
> encode the text, whatever it is, save it, and then un-html-encode it
> when the data is retrieved and displayed.
No, that doesn't make sense. Encoding only makes sense if you use an
encoding that is relevant for where you put the data. Html-encoding data
that goes into the database and then decode it when you read it is a
total waste of time, space and code. It serves no purpose at all.
Also, as you were trying to encode the text on the client side, that
doesn't make it any safer. On the contrary, as you would later decode
this text that you can't safely say that you know is properly encoded,
you would instead open up the security hole that the validation is meant
to help prevent.

> I can't be the only person in history to have encountered this problem
Of course not. I have handled the problem myself several times.

> yet I can't seem to find any examples that satisfy my requirements. I
> thought this page:
> http://www.asp.net/faq/RequestValidation.aspx#5
> had it, but I can't make it work.
Just pick that single property from that page and put in your @.Page
directive. That turns the validation off.
Then you just handle the data as normal, just store it in the database
at it is. When you later put it on a page, make sure that it's properly
html encoded.
Gran Andersson
_____
http://www.guffa.com

Server.HtmlEncode fails with "Server is undefined"

In my application I need to allow users to cut 'n' paste stuff from
various sources, some of which might include dodgy characters such as
"<". Natch, IE interprets these as potentially dangerous and provides
a mechanism to encode/decode them. However I can't seem to get it to
work:

...
<asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px;
POSITION: absolute; TOP: 124px" tabIndex=29 runat="server"
onblur="return ReplaceScriptCode()" Width="553px" Height="52px"
CssClass="STANDARD" Font-Names="Arial" Font-Size="8pt"
TextMode="MultiLine"></asp:textbox>

...

<script language="vb" runat=server>
Public Sub ReplaceScriptCode()
txtDescription.Text = Server.HtmlEncode(txtDescription.Text)
End Sub
</script>

The app. barfs, telling me that "Server is undefined". Thoughts?

Thanks

Edwardteddysnips@.hotmail.com wrote:

Quote:

Originally Posted by

In my application I need to allow users to cut 'n' paste stuff from
various sources, some of which might include dodgy characters such as
"<". Natch, IE interprets these as potentially dangerous and provides
a mechanism to encode/decode them. However I can't seem to get it to
work:
>
...
<asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px;
POSITION: absolute; TOP: 124px" tabIndex=29 runat="server"
onblur="return ReplaceScriptCode()" Width="553px" Height="52px"
CssClass="STANDARD" Font-Names="Arial" Font-Size="8pt"
TextMode="MultiLine"></asp:textbox>
>
...
>
<script language="vb" runat=server>
Public Sub ReplaceScriptCode()
txtDescription.Text = Server.HtmlEncode(txtDescription.Text)
End Sub
</script>
>
The app. barfs, telling me that "Server is undefined". Thoughts?
>
Thanks
>
Edward
>


You are mixing server code and client code. The code in the onblur event
doesn't call the VB subroutine that you have put in the server code, it
calls the client side function with the same name.

As you don't get the error message that ReplaceScriptCode is undefined,
I assume that you also have a Javascript or VBScript function with that
name?

If you have put the same code in that function as in your VB server side
subroutine, that will obviously not work, as there is no Server object
on the client side.

What is it that you are trying to do, really? There is nothing dangerous
about pasting markup code into a textbox. ASP.NET won't let you post
stuff that contains markup code to the server by default, but that is a
completely different thing, and has a completely different solution.

--
Gran Andersson
_____
http://www.guffa.com
Edward

I think your problem is that the OnBlur event, which is calling your
ReplaceScriptCode is a client side event, whereas the Server object is server
side. The code works fine if executed from from code behind:

<asp:TextBox ID="txtDescription" Style="z-index: 102; left:
111px; position: absolute;
top: 124px" TabIndex="29" runat="server" onblur="return
ReplaceScriptCode()"
Width="553px" Height="52px" CssClass="STANDARD"
Font-Names="Arial" Font-Size="8pt"
TextMode="MultiLine"></asp:TextBox>

<script language="vb" runat="server">
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)

txtDescription.Text =
Server.HtmlEncode(txtDescription.Text)
End Sub
</script>

<asp:Button ID="Button1" runat="server" Text="Button" /></div>

Just hit the button to test it.

Hope this helps

Tom

"teddysnips@.hotmail.com" wrote:

Quote:

Originally Posted by

In my application I need to allow users to cut 'n' paste stuff from
various sources, some of which might include dodgy characters such as
"<". Natch, IE interprets these as potentially dangerous and provides
a mechanism to encode/decode them. However I can't seem to get it to
work:
>
...
<asp:textbox id=txtDescription style="Z-INDEX: 102; LEFT: 111px;
POSITION: absolute; TOP: 124px" tabIndex=29 runat="server"
onblur="return ReplaceScriptCode()" Width="553px" Height="52px"
CssClass="STANDARD" Font-Names="Arial" Font-Size="8pt"
TextMode="MultiLine"></asp:textbox>
>
...
>
<script language="vb" runat=server>
Public Sub ReplaceScriptCode()
txtDescription.Text = Server.HtmlEncode(txtDescription.Text)
End Sub
</script>
>
The app. barfs, telling me that "Server is undefined". Thoughts?
>
Thanks
>
Edward
>
>


On 4 Jul, 12:09, Gran Andersson <g...@.guffa.comwrote:

Quote:

Originally Posted by

teddysn...@.hotmail.com wrote:


[...]

Quote:

Originally Posted by

What is it that you are trying to do, really? There is nothing dangerous
about pasting markup code into a textbox. ASP.NET won't let you post
stuff that contains markup code to the server by default, but that is a
completely different thing, and has a completely different solution.


As you say. The problem comes when the user tries to post the text
(dumb of me, I know, I should have mentioned that).

The user wants to be able to paste stuff into text boxes which is then
sent to the server for processing (generally, storage in a database
and later retrieval).

I don't want to remove validation at page level - in fact I doubt the
clients would let me. I rolled my own client-side jscript to strip
out markup code which was called from the OnBlur event, but I thought
I could improve on it using built-in functions.

In short, the requirement is:

ASP.NET with VB code behind.

User pastes stuff into an ASP TextBox

Presses "Save" button. Save button is asp:Button running server-side.

Remove/replace "dangerous" code with HtmlEncoded stuff and save to
database.

Thoughts?

Thanks,

Edward
On 4 Jul, 15:58, Gran Andersson <g...@.guffa.comwrote:

Quote:

Originally Posted by

teddysn...@.hotmail.com wrote:

Quote:

Originally Posted by

On 4 Jul, 12:09, Gran Andersson <g...@.guffa.comwrote:

Quote:

Originally Posted by

teddysn...@.hotmail.com wrote:


[...]

Quote:

Originally Posted by

What is it that you are trying to do, really? There is nothing dangerous
about pasting markup code into a textbox. ASP.NET won't let you post
stuff that contains markup code to the server by default, but that is a
completely different thing, and has a completely different solution.


[...]

Thanks for all your help so far - it really is appreciated.

I reaslise that there's no danger to the database from the text, or
markup code (actually, in the scenario at present, it's simply users
copying and pasting e-mail messages wholesale, including the reply
prefixes e.g. >as seen above which are the main problem). I just
want to allow the users to copy and paste what they want and save this
text to the database without incurring "A potentially dangerous
Request.Form value ... " error. So it seems to make sense to htlm-
encode the text, whatever it is, save it, and then un-html-encode it
when the data is retrieved and displayed.

I can't be the only person in history to have encountered this problem
yet I can't seem to find any examples that satisfy my requirements. I
thought this page:

http://www.asp.net/faq/RequestValidation.aspx#5
had it, but I can't make it work.

Any further ideas before you lose patience completely?

Edward
<teddysnips@.hotmail.comwrote in message
news:1183563744.577845.215450@.m36g2000hse.googlegr oups.com...

Quote:

Originally Posted by

Any further ideas before you lose patience completely?


Would something like this solve your problem:?
http://scriptasylum.com/tutorials/e...ode-decode.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
teddysnips@.hotmail.com wrote:

Quote:

Originally Posted by

On 4 Jul, 15:58, Gran Andersson <g...@.guffa.comwrote:

Quote:

Originally Posted by

>teddysn...@.hotmail.com wrote:

Quote:

Originally Posted by

>>On 4 Jul, 12:09, Gran Andersson <g...@.guffa.comwrote:
>>>teddysn...@.hotmail.com wrote:
>>[...]
>>>What is it that you are trying to do, really? There is nothing dangerous
>>>about pasting markup code into a textbox. ASP.NET won't let you post
>>>stuff that contains markup code to the server by default, but that is a
>>>completely different thing, and has a completely different solution.


[...]
>
Thanks for all your help so far - it really is appreciated.
>
I reaslise that there's no danger to the database from the text, or
markup code (actually, in the scenario at present, it's simply users
copying and pasting e-mail messages wholesale, including the reply
prefixes e.g. >as seen above which are the main problem). I just
want to allow the users to copy and paste what they want and save this
text to the database without incurring "A potentially dangerous
Request.Form value ... " error. So it seems to make sense to htlm-
encode the text, whatever it is, save it, and then un-html-encode it
when the data is retrieved and displayed.


No, that doesn't make sense. Encoding only makes sense if you use an
encoding that is relevant for where you put the data. Html-encoding data
that goes into the database and then decode it when you read it is a
total waste of time, space and code. It serves no purpose at all.

Also, as you were trying to encode the text on the client side, that
doesn't make it any safer. On the contrary, as you would later decode
this text that you can't safely say that you know is properly encoded,
you would instead open up the security hole that the validation is meant
to help prevent.

Quote:

Originally Posted by

I can't be the only person in history to have encountered this problem


Of course not. I have handled the problem myself several times.

Quote:

Originally Posted by

yet I can't seem to find any examples that satisfy my requirements. I
thought this page:
>
http://www.asp.net/faq/RequestValidation.aspx#5
>
had it, but I can't make it work.


Just pick that single property from that page and put in your @.Page
directive. That turns the validation off.

Then you just handle the data as normal, just store it in the database
at it is. When you later put it on a page, make sure that it's properly
html encoded.

--
Gran Andersson
_____
http://www.guffa.com