473,385 Members | 1,474 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,385 software developers and data experts.

Get the javascrit conformation button click in the code behind of c# file in .net

2
I have a master page and a content page in my web page(.net 2008).In the master page i am having some menus.Now after doing some operation in the page if i will click to any other menu then it should ask the conformation by javascript.On cancle it should close the window but in case of ok button click it should save the changes.(I mean want to call the save method in that ok button click)

So can u plz guide me how can i get the event of the javascript conformation ok button click in the c# file.(code behind).Reply me as soon as possible ....................



Thanks
Gitanjali
Mar 24 '08 #1
1 2853
Frinavale
9,735 Expert Mod 8TB
I have a master page and a content page in my web page(.net 2008).In the master page i am having some menus.Now after doing some operation in the page if i will click to any other menu then it should ask the conformation by javascript.On cancle it should close the window but in case of ok button click it should save the changes.(I mean want to call the save method in that ok button click)

So can u plz guide me how can i get the event of the javascript conformation ok button click in the c# file.(code behind).Reply me as soon as possible ....................



Thanks
Gitanjali
The JavaScript "confirm" box returns true if the user selects "ok" and false if the user clicks "cancel". If you set your button's JavaScript "onclick" event to return the value returned by the "confirm" box you can prevent a postback from happening if they click "cancel".

Eg:

Expand|Select|Wrap|Line Numbers
  1. myButton.Attributes.Add("onclick","javascript: return confirm('Do you wish to save your changes?');)
  2.  
This will display a JavaScript confirm box asking "Do you wish to save your changes?". If they click cancel they will remain nothing will happen, if the click "ok" a postback will occur.

Alternatively, if you always want a postback to occur you could set the the onclick to a JavaScript function that saves the confirm value in a HiddenField which you can access on the server.

Eg
Expand|Select|Wrap|Line Numbers
  1. function save(hiddenFieldName)
  2. {    if(confirm('Do you wish to save your changes?')==true)
  3.      {   document.getElementById(hiddenFieldName).value="True";}
  4.      else
  5.      {   document.getElementById(hiddenFieldName).value="False";}
  6.      return true;
  7. }
  8.  
Expand|Select|Wrap|Line Numbers
  1. myButton.Attributes.Add("onclick","javascript: save('"+myAspHiddenField.ClientID+"');")
  2.  
Now in your server side code you can check if you want to save the changes by checking the "myAspHiddenField" value.

-Frinny
Mar 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
5
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter...
5
by: Charlie J | last post by:
I have developed a website with several (30) pages that works just fine on my development machine (XP Pro SP2). When I move the site to the server (W2K3) I have 7 pages where a mouse click on a...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
6
by: shil | last post by:
I have a server side button that needs to do some preperation and afterwards, if everything goes well, open a new browser with a specific url. I know how to execute javascript from a server side...
4
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event....
1
by: Mateo | last post by:
Hi! Let's say You generate button from code. Web forms control, not HTML button. How can I catch it's OnClick event? Where to put code which is exedcuted on buttons OnClick event? Thanx! ...
1
by: aawhan | last post by:
I have a master page and a content page in my web page(.net 2008).In the master page i am having some menus.Now after doing some operation in the page if i will click to any other menu then it should...
1
by: ganesh22 | last post by:
Hi, my requirement is while click the submit button i want to give the conformation that means "Plz check all fields r currect" if ok we can modifie there another button is proceed if i click that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.