I have a class that imports System.Web.UI.Page. The code below works:
public string JScriptEncode(string strValue)
{
strValue = strValue.Replace(@"'", "\x27"); //' JScript encode apostrophes
strValue = strValue.Replace(@"""", "\x22"); //' JScript encode double-quotes
strValue = Server.HtmlEncode(strValue); //' encode chars special to HTML
return strValue;
}
But as soon as I add the keyword "static" to the function, the
Server.HTMLEncode call fails. But if I don't use the "static" keyword, then
my pages cannot access it and use it. Am I missing something here? Is
there another .Net call I should be using instead?
Thanks,
Andrea 4 10631
Try using this syntax instead:
System.Web.HttpContext.Current.Server.HtmlEncode(s trValue);
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl... I have a class that imports System.Web.UI.Page. The code below works:
public string JScriptEncode(string strValue)
{
strValue = strValue.Replace(@"'", "\x27"); //' JScript encode apostrophes
strValue = strValue.Replace(@"""", "\x22"); //' JScript encode
double-quotes strValue = Server.HtmlEncode(strValue); //' encode chars special to HTML
return strValue;
} But as soon as I add the keyword "static" to the function, the Server.HTMLEncode call fails. But if I don't use the "static" keyword,
then my pages cannot access it and use it. Am I missing something here? Is there another .Net call I should be using instead?
Thanks,
Andrea
THANKS!
I knew there had to be a way... :-)
Andrea
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl... Try using this syntax instead: System.Web.HttpContext.Current.Server.HtmlEncode(s trValue);
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message news:Om**************@TK2MSFTNGP11.phx.gbl... I have a class that imports System.Web.UI.Page. The code below works:
public string JScriptEncode(string strValue)
{
strValue = strValue.Replace(@"'", "\x27"); //' JScript encode
apostrophes strValue = strValue.Replace(@"""", "\x22"); //' JScript encode double-quotes strValue = Server.HtmlEncode(strValue); //' encode chars special to HTML
return strValue;
} But as soon as I add the keyword "static" to the function, the Server.HTMLEncode call fails. But if I don't use the "static" keyword,
then my pages cannot access it and use it. Am I missing something here? Is there another .Net call I should be using instead?
Thanks,
Andrea
You are using a instance member of Page, which is Page.Server. Basically, you cannot reference instance members in static methods unless they were passed as parameters.
Luckyily there is a static version of the Server class (System.Web.HttpUtility).
Replace your Server.HtmlEncode with System.Web.HttpUtility.HtmlEncode.
Joe
+1 on this.
"Joe Agster" <an*******@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com... You are using a instance member of Page, which is Page.Server. Basically,
you cannot reference instance members in static methods unless they were
passed as parameters. Luckyily there is a static version of the Server class
(System.Web.HttpUtility). Replace your Server.HtmlEncode with System.Web.HttpUtility.HtmlEncode.
Joe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: abcd |
last post by:
Simple but not working at this moment
I have to fill the HTML select control....
my values could be for example "test number 1"
sample code,
dim x
Data = "test ...
|
by: Michael Gaillez |
last post by:
Hi,
I'm dynamically loading an assembly into an ASP.NET application. In the
control that I load from that dynamic assembly I've tried to use
Server.HTMLEncode but this results in a serious...
|
by: bidllc |
last post by:
I'm working on a minor bug from an open source bug tracking system
(bugtracket.net). It's a great app, but I don't want to bother the
creator any more than I have to, so I thought I'd pose the...
|
by: Marco Miltenburg |
last post by:
While working on some multilingual code I found a rather strange thing
happening with Server.HTMLEncode.
While loading different languages I change the Codepage and Charset in
ASP to reflect the...
|
by: Greg |
last post by:
Hello,
I have a GridView bound to a custom object. I set the DataKeyNames property
along with the column DataField properties at design time, and bind the
GridView to my object at run-time. In...
|
by: hugo |
last post by:
Hi,
I have a function that I call from form fields using the OnKeyUp
function to replace special caracters. Once this function has been
called, it does not set the focus on the form field where...
|
by: webaccess |
last post by:
Hi Friends ..!!
I want to use datagrid/dataview control to data in tablular format,also I want to add paging and format the data of table column.
Problem is data is coming from API Dom in as...
|
by: =?Utf-8?B?R1ROMTcwNzc3?= |
last post by:
Hi Guys,
It's been a while, I've got a small problem that I could do with your
expertise on.
As you know (I Think) I build websites for recruitment agencies, part of the
website includes a job...
|
by: yogarajan |
last post by:
hello friend
i need urgent help
this is my aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Reguserdetailstest.aspx.cs" Inherits="Reguserdetailstest" %>
<!DOCTYPE html...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |