Properly process user input or QueryStrings as int

Posted on: Thu Aug 20 11:29:37 -0700 2009. Updated on: Thu Aug 20 11:30:11 -0700 2009.
Category: DotNet

Quick code to process incoming querystrings or other user input, ie textboxes from a string to an int.

int messageId;
if (int.TryParse(Request.QueryString["messageId"], out messageId) == false)
{
    messageId = -1; // default value for messageId, ie to create a new item.
}

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.