473,387 Members | 1,592 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.

call javascript from code behind

Ok, here is my story. I took over a web site that is using the asp.net wizard. This wizard has buttons within it, now, on one of the steps in the wizard I have a drop down. Depending if 'Delete' is selected in the drop down, I need to show a message box to ask the user 'you sure you want to delete?" if they click 'OK' it deletes, if they click cancel it does nothing.

So within the button click event, how can I show an confirmation box only if 'Delete' is selected in the drop down?

so I need something like this

if (dd.selecteditem.text == "delete")
{
I need to show a confirmation box;
}

then call my delete method only if 'OK' is clicked in the confirmation box, if cancel then nothing happens.

any suggestions on how this can be done?


Oct 4 '07 #1
2 3039
You could do something like this:

if (dd.selecteditem.text == "delete")
{

ClientScript.RegisterClientScriptBlock(this.GetTyp e(), "DeletePopup", "<script>
confirm('Are you sure you want to delete?') </script>");

}

That'll pop up a JavaScript box with OK and Cancel as options and the text
can be programatically changed to include row information, etc.

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com
Ok, here is my story. I took over a web site that is using the asp.net
wizard. This wizard has buttons within it, now, on one of the steps in
the wizard I have a drop down. Depending if 'Delete' is selected in
the drop down, I need to show a message box to ask the user 'you sure
you want to delete?" if they click 'OK' it deletes, if they click
cancel it does nothing.

So within the button click event, how can I show an confirmation box
only if 'Delete' is selected in the drop down?

so I need something like this

if (dd.selecteditem.text == "delete")
{
I need to show a confirmation box;
}
then call my delete method only if 'OK' is clicked in the confirmation
box, if cancel then nothing happens.

any suggestions on how this can be done?

Oct 4 '07 #2
On Oct 4, 10:27 pm, "Mike" <M...@community.nospam.comwrote:
Ok, here is my story. I took over a web site that is using the asp.net wizard. This wizard has buttons within it, now, on one of the steps in the wizard I have a drop down. Depending if 'Delete' is selected in the drop down, I need to show a message box to ask the user 'you sure you want to delete?" if they click 'OK' it deletes, if they click cancel it does nothing.

So within the button click event, how can I show an confirmation box only if 'Delete' is selected in the drop down?

so I need something like this

if (dd.selecteditem.text == "delete")
{
I need to show a confirmation box;

}

then call my delete method only if 'OK' is clicked in the confirmation box, if cancel then nothing happens.

any suggestions on how this can be done?


Hi Mike,

You'd want to use the OnClientClick property of the button, which
calls a javascript function..

<asp:Button ID="Button1" runat="server" OnClientClick="return
MyFunction()" Text="My Button" />

and in your javascript

function MyFunction() {
if (dd.selecteditem.text != "delete") return true;
return confirm("you sure you want to delete?");
}

Some docs with examples here:
http://msdn2.microsoft.com/en-us/lib...ientclick.aspx

--
Collin

Oct 4 '07 #3

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

Similar topics

8
by: Jade | last post by:
I saw some web page saying I could do it this way in javascript: var iNumber = <%#publicvarname publicpropertyname %> but it doesn't seem to work. I have this piece of code here in...
1
by: Nevyn Twyll | last post by:
I have a DataList; in the DataList's , I have a LinkButton and a few listboxes. When the LinkButton is pressed, I need to get the ID of the selected item in one of the Listbox controls. Then I...
5
by: Chung | last post by:
Hi All, Can anyone tell me how can I call a client script (javascript) from Code behind server code (c#)? Chung
4
by: Nevyn Twyll | last post by:
I have a web form, with c# code-behind. I have a listbox on the form, bound to a dataset. I want to have 2 buttons/hyperlinks/etc. beside the listbox. When they are clicked, I want to launch a...
3
by: rodchar | last post by:
hey all, i have a server-side button on my webform and was wondering if i can call an external javascript that's in the same application direcory? If so, can someone please show me the syntax? ...
3
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are...
5
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
1
by: supin | last post by:
hi, i work in asp.net2.0/c#.not much expert in javascript.i have a variable declared in the c# code behind page.assume the variable contains some value. i have a javascript function in the...
4
by: sajithkahawatta | last post by:
i want to call a java script function from code behind. in page1.aspx page i placed script' <script language="javascript"> function SetSelected() { infoTextBox.select(); } </script>
2
by: wolverine2512 | last post by:
Hello .Net Wizards! I would like to seek your help on how to call javascript function from code behind of VB.net. I have javascript function named Openform() and i want to execute it on page load,...
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...
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:
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...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.