How to include IsValid in nonASP.NET approach button (standard html)

I know that ASP.NET controls like a button have a postback event model. And check if the page.IsValid file is dependent on events and postback to check.

But what if I have a button that uses plain HTML inside my .aspx (and I don’t want to use the asp.net button ... please don’t ask me why), but still want to use the .IsValid page call?

For example, let's say my .aspx page has 2 buttons:

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

and it was on the page, someone else created it some time ago. In cmdPlaceOrder we check the value of Page.IsValid:

protected void cmdPlaceOrder_Click(object sender, EventArgs args)
{

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

. , nonASP.NET, .aspx, ( , ):

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

, ( URL). URL- querystring, , , , , , , ​​:

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
}

, , , Page.IsValid :

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.

, , .aspx. , ASP.NET( , , , ).

, - Page.IsValid, , , . , - , - .

. Validate(); PlaceGoogleCheckoutOrder() Page.IsValid, .

MSDN .Validate() (http://msdn.microsoft.com/en-us/library/0ke7bxeh.aspx) : " . , ."

, . , ASP.NET , ( ), , . , runat = "server"... , , .

+3
1

, , href URL-. , , , , .

, (<a >), , onclick javascript, , javascript __doPostBack().

__doPostBack() msdn :
http://msdn.microsoft.com/en-us/library/aa720099(VS.71).aspx
.Net 1.1, .

+3

Source: https://habr.com/ru/post/1731567/


All Articles