Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 794083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:15:32+00:00 2026-05-14T22:15:32+00:00

It it possible to enable validation in an ASP.NET GridView purely declaratively? What I’ve

  • 0

It it possible to enable validation in an ASP.NET GridView purely declaratively?

What I’ve tried:

  • A GridView bound to an ObjectDataSource with SelectMethod and UpdateMethod defined

  • The GridView contains some ReadOnly BoundField columns and a TemplateField whose EditTemplate contains a TextBox and a RegularExpressionValidator that only allows numeric input in the TextBox.

  • The GridView also contains a CommandField with ShowEditButton=true and CausesValidation=true.

If I click on Edit, enter an invalid value, then click on Save, there is a PostBack, and an exception is thrown in the server (Input string was not in a correct format).

I can of course avoid this by adding validation code to the RowUpdating event handler on the server (see below), but is there any declarative way to force the validation to be done without adding this code?

protected void MyGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    Page.Validate("MyValidationGroup");
    if (!Page.IsValid)
    {
        e.Cancel = true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:15:32+00:00Added an answer on May 14, 2026 at 10:15 pm

    You need that code.

    “In addition to relying on client side validation, it is also important that you call Page.IsValid when handling the postback event.”

    http://weblogs.asp.net/rajbk/archive/2007/03/15/page-isvalid-and-validate.aspx

    update

    To avoid boiler plate code, you could have all pages inherit from a base class and all user controls inherit from a different base class. The base class will have the common logic (like the one above). You then have to either manually wire it up or walk through the control tree and automatically wire up the events.

    I would personally stick with what you currently have though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to enable C# source code formatting inside array initializers in VS.NET
Anyone know if its possible to enable horizontal scrolling ONLY in a windows forms
In bash, I believe it is possible to enable tab completion on the terminal
Is it possible to programmatically enable Desktop Sync for a folder via the Box.com
Possible Duplicate: How to use enable_if to enable member functions based on template parameter
Possible Duplicate: How can I disable/enable UISearchBar keyboard's Search button? Can we disable the
Is it possible to disable or enable subgrid based on the selected value when
It's possible to implement INotifyCollectionChanged or other interface like IObservable to enable to bind
Is it possible to enable task tags like //TODO and //FIXME for html files
Is it possible to enable RDS for ColdFusion 8 on a server that requires

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.