Celebration
Celebration

Reputation: 1

call jQuery function from code behind after postback

I'm trying to call a jQuery .click function after page postback from code behind. I'm using ASP.NET with C#.

Upvotes: 0

Views: 8351

Answers (2)

InvisibleBacon
InvisibleBacon

Reputation: 3222

If you want to call the click function for an element after the page has successfully reloaded from a postback, you can make use of the RegisterStartupScript function:

Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "$('#myElement').click();", true);

Upvotes: 1

joshperry
joshperry

Reputation: 42297

The easiest thing to do would be to use jQuery to attach to the submit event of the form and do whatever processing you require before the postback.

$('#form-id').submit(function() {
    // Do whatever here
});

Also, if you return true from this event handler the postback will occur, if you return false then the page postback will be prevented.

Upvotes: 2

Related Questions