PDA

View Full Version : asp button with javascript...


many_tentacles
06-10-2009, 05:57 PM
Hi

I have this asp button:

<asp:Button runat="server" ID="callback_button" Text="Submit" CssClass="callbackbutton" OnClick="request_callback" />

I somehow need to incorporate this javascript into the onclick part of the code:

onclick="exit=false"

Is there any way I can make this work?? If you need more code just let me know and I'll try to simplify the rather large page it comes from.

Thanks

many_tentacles
06-10-2009, 06:36 PM
Ok... so I took the time to simplify it... It's the asp button at the bottom that I need to add the javascript to...

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Web.Mail" %>

<script runat="server">

Sub submit_reservation_request(sender as Object, e as EventArgs)

Dim objMM as New MailMessage()

objMM.From = "address@address.com"

objMM.To = "me@address.co.uk"

objMM.BodyFormat = MailFormat.Text

objMM.Priority = MailPriority.Normal

objMM.Subject = "Test"

objMM.Body = "Here is the test email body"

SmtpMail.SmtpServer = "localhost"

SmtpMail.Send(objMM)

response.Redirect("default.aspx")

End Sub

</script>

<html>
<head>
<title>Page title</title>
<script type="text/javascript" language="javascript">

var exit=true;
function showpopup(){
if(exit){
var popup = window.open("popup.html",'Help','width=450,height=650,scrollbars=no,resize=no');
}
}

</script>
</head>

<body onunload=showpopup()>
<form id="availform" runat="server">

<asp:TextBox ID="txtReserveName" runat="server" Text="Full name" ></asp:TextBox>

<br /><br />

<asp:Button runat="server" ID="btnReserve" Text="Submit" OnClick="submit_reservation_request" />

</div>

</form>
</body>
</html>

Mike_O
06-10-2009, 10:56 PM
Hey,

Inside a server-side Page_Load() function, put:

callback_button.Attributes.Add("onclick","exit=false");

Mike

bermanbp
06-11-2009, 12:05 AM
There is also the asp.net OnClientClick property that you can use for exactly this. I'd try this first.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx

many_tentacles
06-11-2009, 12:45 PM
Thanks bermanbp

<asp:Button runat="server" ID="btnReserve" Text="Submit" OnClick="submit_reservation_request" OnClientClick="exit=false" />

Exactly what I was after. Simple when you know what how!