Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Thursday, March 29, 2012

server side validation

Hi,
Does anybody has a simple example (other than what is on Microsoft's site) of how to do server side validation? I simply can not get it to work and Microsoft example is king of vague to me. All I am trying to do is compare the value of a textbox against a database value and reject if it is not valid. So if the query
select* from thistable where name=textboxvalue
returns zero rows then the validator should fail.
Thanks,
Mo
Can you show the code that you are using that doesn't work? Maybe its just a little tweak away from working
1. Use a CustomValidator with its EnableClientScript property set to false (since you only can do server side validation)
2. In the ServerValidate method, write code that checks with the database. It should set the args parameter's IsValid property to true if the validator should succeed and false if it should fail.
3. You should have a post back event handler for each submit control. For example, Buttons have a Click event. Inside that code, test Page.IsValid is true before saving data. If you are not using any of the buttons or if the Button control's CausesValidation property is set to false, first call Page.Validate() before testing IsValid.
To learn all kinds of things about validation, see this article:www.aspalliance.com/699.

Server side variables (e.g. $_SERVER['REMOTE_ADDR']) - dotNet equivalent?

What is the equivalent for retrieving server side variables?
For example in PHP, one such predefined variable is: $_SERVER['REMOTE_ADDR']"Frank Moyles" <fgmoyles@.nospam.com> wrote in message
news:ceKdne8KddpqoenaRVnyjwA@.bt.com...
> What is the equivalent for retrieving server side variables?
> For example in PHP, one such predefined variable is:
> $_SERVER['REMOTE_ADDR']
string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"].ToString();
Mark Rae
ASP.NET MVP
http://www.markrae.net
"Gran Andersson" <guffa@.guffa.com> wrote in message
news:uIV97CVSIHA.4584@.TK2MSFTNGP03.phx.gbl...

> The ServerVariables collection is a collection of strings, so just do:
> string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"];
> Besides, the collection returns null if there is no item by the specified
> name, and calling ToString on a null reference causes an exception.
You're quite correct - I should have been more specific.
Mark Rae
ASP.NET MVP
http://www.markrae.net

Saturday, March 24, 2012

Server.execute

Hi,
I face a problem
is it possible to access an asp/vbscript variable created in the parent by t
he child in the server.execute.
If so an example block.
TIA.
Raj.going to have to either pass it (form, querystring) or store it and read it
back in (application var, db, cookie, session, etc).
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Raj" <Raj@.discussions.microsoft.com> wrote in message
news:19B6E194-6F51-4EBC-8AD2-CA3330F22E89@.microsoft.com...
> Hi,
> I face a problem
> is it possible to access an asp/vbscript variable created in the parent by
the child in the server.execute.
> If so an example block.
> TIA.
> Raj.

Thursday, March 22, 2012

Server.HTMLEncode

Hi,
The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]
---
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".
[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
---
However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."
Am I missing something? Am I not using the correct encoding method?
Any assistance gratefully received.
Best,
Mark RaeHi,
Use Server.UrlEncode for the output you are expecting.
"Mark Rae" <mark@.mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eBm3iJ$cEHA.592@.TK2MSFTNGP11.phx.gbl...
Hi,
The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]
---
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".
[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
---
However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."
Am I missing something? Am I not using the correct encoding method?
Any assistance gratefully received.
Best,
Mark Rae
Mark Rae wrote:

> Hi,
> The following is lifted straight from the MSDN help topic for
> HttpServerUtility.HtmlEncode Method [C#]
> ---
> The following example encodes a string for transmission by HTTP. It encode
s
> the string named TestString, which contains the text "This is a <Test
> String>.", and copies it into the string named EncodedString as
> "This+is+a+%3cTest+String%3e.".
> [C#]
> String TestString = "This is a <Test String>.";
> StringWriter writer = new StringWriter();
> Server.HtmlEncode(TestString, writer);
> String EncodedString = writer.ToString();
> ---
> However, when I run it, the value of EncodedString is "This is a <Test
> String>." not "This+is+a+%3cTest+String%3e."
> Am I missing something? Am I not using the correct encoding method?
> Any assistance gratefully received.
> Best,
> Mark Rae
>
Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
would be expected to.
-Mike
"Mike Newton" <MNewton@.Addus.com> wrote in message
news:ewkETQ$cEHA.2236@.TK2MSFTNGP10.phx.gbl...
Mike & Silva,

> Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
> would be expected to.
Thanks very much. Is the MSDN topic wrong, then...?

Server.HTMLEncode

Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]

-------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
-------------------

However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark RaeHi,

Use Server.UrlEncode for the output you are expecting.

"Mark Rae" <mark@.mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:eBm3iJ$cEHA.592@.TK2MSFTNGP11.phx.gbl...
Hi,

The following is lifted straight from the MSDN help topic for
HttpServerUtility.HtmlEncode Method [C#]

-------------------
The following example encodes a string for transmission by HTTP. It encodes
the string named TestString, which contains the text "This is a <Test
String>.", and copies it into the string named EncodedString as
"This+is+a+%3cTest+String%3e.".

[C#]
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();
-------------------

However, when I run it, the value of EncodedString is "This is a <Test
String>." not "This+is+a+%3cTest+String%3e."

Am I missing something? Am I not using the correct encoding method?

Any assistance gratefully received.

Best,

Mark Rae
Mark Rae wrote:

> Hi,
> The following is lifted straight from the MSDN help topic for
> HttpServerUtility.HtmlEncode Method [C#]
> -------------------
> The following example encodes a string for transmission by HTTP. It encodes
> the string named TestString, which contains the text "This is a <Test
> String>.", and copies it into the string named EncodedString as
> "This+is+a+%3cTest+String%3e.".
> [C#]
> String TestString = "This is a <Test String>.";
> StringWriter writer = new StringWriter();
> Server.HtmlEncode(TestString, writer);
> String EncodedString = writer.ToString();
> -------------------
> However, when I run it, the value of EncodedString is "This is a <Test
> String>." not "This+is+a+%3cTest+String%3e."
> Am I missing something? Am I not using the correct encoding method?
> Any assistance gratefully received.
> Best,
> Mark Rae

Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
would be expected to.

-Mike
"Mike Newton" <MNewton@.Addus.com> wrote in message
news:ewkETQ$cEHA.2236@.TK2MSFTNGP10.phx.gbl...

Mike & Silva,

> Try Server.UrlEncode instead. HtmlEncode is generating HTML, as it
> would be expected to.

Thanks very much. Is the MSDN topic wrong, then...?