I have a class that imports System.Web.UI.P age. The code below works:
public string JScriptEncode(s tring strValue)
{
strValue = strValue.Replac e(@"'", "\x27"); //' JScript encode apostrophes
strValue = strValue.Replac e(@"""", "\x22"); //' JScript encode double-quotes
strValue = Server.HtmlEnco de(strValue); //' encode chars special to HTML
return strValue;
}
But as soon as I add the keyword "static" to the function, the
Server.HTMLEnco de 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 10659
Try using this syntax instead:
System.Web.Http Context.Current .Server.HtmlEnc ode(strValue);
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message
news:Om******** ******@TK2MSFTN GP11.phx.gbl... I have a class that imports System.Web.UI.P age. The code below works:
public string JScriptEncode(s tring strValue)
{
strValue = strValue.Replac e(@"'", "\x27"); //' JScript encode apostrophes
strValue = strValue.Replac e(@"""", "\x22"); //' JScript encode
double-quotes strValue = Server.HtmlEnco de(strValue); //' encode chars special to HTML
return strValue;
} But as soon as I add the keyword "static" to the function, the Server.HTMLEnco de 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.ne t> wrote in message
news:O4******** ******@TK2MSFTN GP11.phx.gbl... Try using this syntax instead: System.Web.Http Context.Current .Server.HtmlEnc ode(strValue);
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:Om******** ******@TK2MSFTN GP11.phx.gbl... I have a class that imports System.Web.UI.P age. The code below works:
public string JScriptEncode(s tring strValue)
{
strValue = strValue.Replac e(@"'", "\x27"); //' JScript encode
apostrophes strValue = strValue.Replac e(@"""", "\x22"); //' JScript encode double-quotes strValue = Server.HtmlEnco de(strValue); //' encode chars special to HTML
return strValue;
} But as soon as I add the keyword "static" to the function, the Server.HTMLEnco de 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.Htt pUtility).
Replace your Server.HtmlEnco de with System.Web.Http Utility.HtmlEnc ode.
Joe
+1 on this.
"Joe Agster" <an*******@disc ussions.microso ft.com> wrote in message
news:83******** *************** ***********@mic rosoft.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.Htt pUtility). Replace your Server.HtmlEnco de with System.Web.Http Utility.HtmlEnc ode.
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 number 1"
|
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 performance loss. Is there
anyone who knows why or is there an alternative for server.htmlencode
method? Without the server.htmlencode the thingy works very fine.
greetz
|
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 question
here.
The problem is with an email that gets sent from the system. In a
nutshell, it's an HTML format email that is choking on the string that
is returned form this function that is added to the email's body:
|
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 language. This all works fine. However when I tried
to use Charset UTF-8 with Codepage 65001 everywhere I found that
HTMLEncode always translates all UTF-8 characters to &#xxxx.
Example:
|
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 the RowDeleting event, I try to access
the DataKeys property, but it contains no elements.
This is the first time I'm trying to use DatKeyNames and DataKeys. What am
I missing here?
| |
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 I have
called the function from.
What happens :
I laod a EDIT page with a html form on it and fill in the fields with
|
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 XML source. Now to display data i hv use dataset to fetch data.so i m displaying data in datagrid/dataview.
Now here comes a problem:
Using Datagrid :
|
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 board facility and for job form entry I used a normal
form with a normal textbox, however what I'm finding now is that a lot of
recruitment consultants are pasting the job description into the textbox,
which when submitted is resulting in most of...
|
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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |