button handler problem

G

Guest

i have a c# asp.net webform that has a "Close" button. When the user clicks
the Close button, a message box saying "do u want to save to database...?".
the problem is that the statements inside the Close function are not being
executed. how can i save the data in the webform to the database? can i show
a message box without using javascript? can i call a function defined in the
code behind from within javascript? thanks in advance.

code behind:
private void Page_Load(object sender, System.EventArgs e)
{
//btnClose.Attributes.Add("OnClick", "javascript:Close()");
btnClose.Attributes.Add("OnMouseDown", "javascript:Close()");
.......
}

private void btnClose_Click(object sender, System.EventArgs e)
{
if (txtClose.Text == "1")
{

InsertToDatabase();
}
Response.Redirect("taskOrderSummary.aspx");
}

html code in aspx page:
<script type="text/javascript">
function Close(){
var agree=confirm("Do you wish to save changes?");
if (agree)
{
document.Form1.txtClose.value = 1 ;
}
else
{
document.Form1.txtClose.value = 0 ;
}
}
 
G

Guest

i recomend to doit so...

private void Page_Load(object sender, System.EventArgs e)
{
btnClose.Attributes.Add("OnClick", "javascript:return Close()");
.......
}


function Close(){
return confirm("Do you wish to save changes?");
}



ps: i think you have the handler declaration for the click button in the
behind code...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top