3

I have an asp:Button control like this;

<asp:Button ID="btnPayCC" CssClass="paymentButton" runat="server" Text="ONAYLA"  
OnClientClick="if(!doPostBack()) return false; frmMaster.target='_blank'" 
PostBackUrl="http://www.google.com" OnClick="btnPayCC_Click" />

And doPostBack javascript function is;

function doPostBack() 
 {
   __doPostBack('<%= btnPayCC.ClientID %>', '');
   return true;
 };

When I clicked the button, then it opens new page(google.com) as I wish, But do not postback into button control's OnClick event.

What is the problem? How can I solve it?

4
  • 3
    You can only PostBack to one place. You're either posting "back" to the google url or you're posting back to your own page. Both can't happen without separate requests. Commented Mar 27, 2013 at 15:07
  • Thanks @JoelEtherton, I wonder, is there any alternative solution to do this job (calling a c# function using doPostBack vs.)? Commented Mar 27, 2013 at 15:09
  • I would recommend posting back to your local page, doing whatever verification you need then REposting to google. They are self-contained actions so shouldn't be dependent on each other. Commented Mar 27, 2013 at 15:43
  • @MehmetInce you can call your javascript from the code behind. Commented Mar 27, 2013 at 16:58

1 Answer 1

5

I had the same problem. I solved it by adding a Response.Redirect("url") at the end of my onClick event for the Button and removing the PostbackUrl attribute from the button so that is uses autopostback to the same url. IE:

protected void Button_Click(object sender, EventArgs e)
{ 
   //do your button click events here
   Response.Redirect("~/url.aspx");
}

and

<asp:Button ID="Button" runat="server" CausesValidation="false" OnClick="Button_Click">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.