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

  • Home
  • SEARCH
  • 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 594265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:56:06+00:00 2026-05-13T15:56:06+00:00

I know that ASP.NET controls such as the button have the postback event model.

  • 0

I know that ASP.NET controls such as the button have the postback event model. And checking whether the page.IsValid is dependent on events and postback in order for the validation to kick in.

But what if I have a button using regular HTML inside my .aspx (and I don’t want to use the asp.net button…please do not ask me why) yet still want to take advantage of calling Page.IsValid?

For example, lets say my .aspx page has 2 buttons:

<asp:ImageButton runat="server" ID="cmdPlaceOrder" OnClick="cmdPlaceOrder_Click" ImageUrl="images/someButton.gif" />

and that was there in the page, someone else had created that a while back. In the cmdPlaceOrder we check for Page.IsValid:

protected void cmdPlaceOrder_Click(object sender, EventArgs args)
{

    if (!IsValid)
        return;
    ... rest of logic
}

That’s standard. Now what if I add a non-ASP.NET button like this in the .aspx page, used to place the order (but for a different kind of order seperate from the existing place order button above):

<a href="<%=SomeUrl() %>"><img src="images/buttonPayGoogleCheckout.gif" alt="Pay with Google"/></a>

So on click of the hyperlink, the page posts back to itself (same url). I check the url for a querystring param flag that if set calls the method below that I created which is basically a similar method as the above but with a bit of different logic in it:

protected void PlaceGoogleCheckoutOrder()
{

    if (!IsValid)
        return;
    ... rest of logic here, but I can't get to it because there is no event model to allow IsValid to work
}

Obviously I’m not tying in an event model to this therefore once it hits the check for Page.IsValid it errors with the following message at runtime:

Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate.

But I still want to be able to call this validation, the validation that’s already been setup in our .aspx. I don’t want to reinvent the wheel on this and I don’t in this case want to use an ASP.NET based button (do not ask me why, I have my reasons and it’s too long to get into that).

I want to know how I can still get that Page.IsValid check to work for a non-event driven button using . I’m not sure how to hook up an event to do so that still hooks in after the redirect and allows that code to still validate.

I tried adding Page.Validate(); inside my PlaceGoogleCheckoutOrder() method right before the check for Page.IsValid but I still get the same error.

After looking at MSDN on Page.Validate() (http://msdn.microsoft.com/en-us/library/0ke7bxeh.aspx) and it states “The validation group is determined by the control that posted the page to the server. If no validation group is specified, then no validation group is used.”

So that’s why nothing happened. So I’m not sure how to get ASP.NET in this case to know about the control (in this case my ) that posted the page to the server so that a validation group IS used. I guess I could add a runat=”server” to my …but doubt that’s all I need to do here.

  • 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-13T15:56:07+00:00Added an answer on May 13, 2026 at 3:56 pm

    The trick with your normal button is that it never does a post back because your href attribute has some other url there. If you want to check if the page is valid, you have to post back to your page class first to make that check and then redirect from there.

    What you can do to make this happen with a normal anchor (<a >) tag is process that anchor’s onclick event in javascript, do any client side work you want, and then call the __doPostBack() javascript function.

    You can see an example of how to call __doPostBack() on msdn here:
    http://msdn.microsoft.com/en-us/library/aa720099(VS.71).aspx
    It’s from .Net 1.1, but still accurate.

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

Sidebar

Ask A Question

Stats

  • Questions 297k
  • Answers 297k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm guessing you actually wrote [<EntryPoint>] let Main(args) = let… May 13, 2026 at 7:14 pm
  • Editorial Team
    Editorial Team added an answer Look into SQLite pragma-s. http://www.sqlite.org/pragma.html PRAGMA locking_mode; PRAGMA locking_mode =… May 13, 2026 at 7:14 pm
  • Editorial Team
    Editorial Team added an answer To answer your real question, which is I have code… May 13, 2026 at 7:14 pm

Related Questions

I know that almost everything is already said about CMSs, but what interests me
I am trying to teach ASP.NET MVC to students (undergrads) that have been studying
I have some experience in ASP.Net and can work my way around it without
I'm working on a website in ASP.NET/C# and I'd like to make it possible
When I'm working with DataBound controls in ASP.NET 2.0 such as a Repeater, I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.