473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

button handler problem

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 ;
}
}

Nov 17 '05 #1
2 4032
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...
"Newbie" wrote:
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 ;
}
}

Nov 17 '05 #2
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...
"Newbie" wrote:
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 ;
}
}

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: yfng | last post by:
In a web form, I want the user clicks on one button and this button will trigger another button/link which will open a new browser window? How to do that? Is there any method like...
3
by: Jason Kyle Baginski | last post by:
Here's a little test app to demonstrate a problem I'm having. It creates four buttons, each one with the different FlatStyle types available. Three of them behave exactly the same way(and the...
1
by: Olav Tollefsen | last post by:
I have a rather fundamental ASP.NET question. On my page I have a search text box for user input, a button (which invokes a event handler on the page) and a user control to display the results....
3
by: Russell | last post by:
I have a web page that i am using an image button as my submit button. The code behind the button works, but when I click enter on the web page, nothing happens. Can anybody tell me how to get my...
3
by: Shimon Sim | last post by:
I put linkbutton in a repeater header. I attached event handler in makeup as onclick="btnSort_Click". Made btnSort_Click method public. It doesn't fire if I click on it. I tried to attach it in...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
1
by: Gary Paris | last post by:
On my windowsform, I have a tab control. On the control, I have as button called btnSave. I wanted to move the button off the tab control and onto the windowsform. Shouldn't be a problem I...
21
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
6
by: Joseph Geretz | last post by:
I'm porting a C# Outlook Addin originally engineered as a COM Addin over to use VSTO. I've gotten this to the point where my VSTO Addin installs its Menu items and Toolbar buttons when Outlook...
1
by: AE_Cory | last post by:
I'm a n00b to Visual C++ and OOP, but not to programming in general. Here's the problem: Not knowing what I'm doing, I've made my VC++ application as a CLR Window Forms project. Now, I have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.