Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

call javascript from code behind

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 04 Oct 2007 15:27 GMT
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?
David R. Longnecker - 04 Oct 2007 16:15 GMT
You could do something like this:

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

ClientScript.RegisterClientScriptBlock(this.GetType(), "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
[quoted text clipped - 16 lines]
>
> any suggestions on how this can be done?
Collin Chung - 04 Oct 2007 16:30 GMT
> 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.
>
[quoted text clipped - 11 lines]
>
> 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/library/system.web.ui.webcontrols.button.onclie
ntclick.aspx


--
Collin

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.