asp button onclick reloads the parent page
I have a button and added onlcik event from the code behind. When I click on the button it reloads the parent page. What could be the problem? Please let me know.
<asp:Button ID="btnReport" runat="server" Text="Report"/>
Code behind:
string url = "http://www.google.com";
Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWin",
"<script language=javascript>function Report() { window.open ('" +
url + "', null,'top=1,left=1,center=yes,resizable=no,Width=840px,
Height= 300px,status=no,titlebar=no;toolbar=no,
menubar=no,location=no,scrollbars=yes')开发者_如何学编程;}</script>");
btnReport.Attributes.Add("OnClick", "Report()");
I think you should actually use the OnClientClick
attribute:
btnReport.Attributes.Add("OnClientClick", "Report()");
精彩评论