admin管理员组

文章数量:1384803

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="" 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) as I wish, But do not postback into button control's OnClick event.

What is the problem? How can I solve it?

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." 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.) as I wish, But do not postback into button control's OnClick event.

What is the problem? How can I solve it?

Share Improve this question edited Dec 3, 2013 at 12:24 Mehmet Ince asked Mar 27, 2013 at 15:04 Mehmet InceMehmet Ince 4,18914 gold badges47 silver badges65 bronze badges 4
  • 2 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. – Joel Etherton 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.)? – Mehmet Ince Commented Mar 27, 2013 at 15:09
  • I would remend 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. – Joel Etherton Commented Mar 27, 2013 at 15:43
  • @MehmetInce you can call your javascript from the code behind. – Nudier Mena Commented Mar 27, 2013 at 16:58
Add a ment  | 

1 Answer 1

Reset to default 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">

本文标签: cUsing OnClick event with PostBackUrl attribute of aspButtonStack Overflow