vellaima Posted April 14, 2003 Posted April 14, 2003 Hi, Dim scripts1 as String="<script>confirm('Are you sure?')"+"</"+"script>" RegisterClientScriptBlock("alert1",scripts1) In the above code i would like to capture whether the user has clicked Yes/No and do validations in the server accordingly. Is it possible? - Vidhya Quote
bungpeng Posted April 15, 2003 Posted April 15, 2003 Just continue all your javascript source code in "scripts1" variable like in normal HTML page or I misunderstand your question? Quote
vellaima Posted April 15, 2003 Author Posted April 15, 2003 I have found out as to how to go about for it. Sub Page_Load(Source As Object, E As EventArgs) cls.Attributes.Add("onclick","return confirm('Are you Sure you want to delete?');") End Sub Sub clsthread(Source As Object, E As EventArgs) Dim scripts as String ="<script>alert('The record is deleted')"+"</"+"script>" RegisterClientScriptBlock("alert1",scripts) End Sub Here "cls" is the ASP Control Button. - Vidhya Quote
bungpeng Posted April 16, 2003 Posted April 16, 2003 Let me guess what are you going to do: 1. When user press the delete button, you ask them ("Are you sure you want to delete"?") 2. If user press "OK", then you delete record in your database? (do nothing if user press "Cancel") 3. If record deleted then you prompt message "The Record is deleted" If this is right: I hope you will understand the different between server and client when you use javascript (client) with ASP.NET(server). From Javascript, if you want to run ASP.NET, you need a PostBack (submit form), because you need to submit your page to server site. It means when user press "OK" to delete record, then you need to submit your page, otherwise do nothing (using Javascript to handle this). Delete record using ASP.NET in server site, then prompt message in client site using javascript If I not mistaken (long time no use), the Javascript code to capture the confirmation is if (confirm("Are you sure..")) { ' submit your form to server } else { ' do nothing... you no need this block actually...:) } [/Quote] Quote
vellaima Posted April 16, 2003 Author Posted April 16, 2003 Bungpeng, to my understanding I have done the same thing as you have mentioned. In the Page Load i have added an attribute for the "cls" button. The attribute i have added is On Clicking this button the JavaScript is getting fired. If the user clicks "Ok" then the clsthread method is executed. If he clicks "Cancel" then it is not executed. Please do excuse me if the method of explanation is incorrect. -Vidhya Quote
bungpeng Posted April 16, 2003 Posted April 16, 2003 How do you call "clsthread" method from javascript? As what I understand, "clsthread" is ASP.NET code right? We can't call ASP.NET function in javascript. Quote
vellaima Posted April 16, 2003 Author Posted April 16, 2003 I am pasting the sample code for easy understanding. <%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(Source As Object, E As EventArgs) cls.Attributes.Add("onclick","return confirm('Are you Sure you want to delete?');") End Sub Sub clsthread(Source As Object, E As EventArgs) Dim scripts as String ="<script>alert('The record is deleted')"+"</"+"script>" RegisterClientScriptBlock("alert1",scripts) End Sub </script> <html> <head> </head> <body> <form runat="server"> <asp:Button id="cls" onclick="clsthread" runat="server" Text="Close Thread"></asp:Button> </form> </body> </html> Quote
bungpeng Posted April 16, 2003 Posted April 16, 2003 No, your code won't work. You assign 2 events to your 'cls' button, one is onclick="clsthread" and another one is through cls.Attributes.Add ... it is wrong. My question: where are you going to place your process? Quote
vellaima Posted April 16, 2003 Author Posted April 16, 2003 Please do try the sample code by copying and pasting it as an aspx file. It worked perfectly for me. Quote
vellaima Posted April 16, 2003 Author Posted April 16, 2003 Bungpeng, please do go the following site to get the better understanding of Attributes.Add http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconWebFormsEventModel.asp Quote
bungpeng Posted April 16, 2003 Posted April 16, 2003 Sorry, I am wrong from beginning, because I thought you still got problem in your code... furthermore, I thought I know quite well with web application architecture (client/server), but I dunno in ASP.NET, it was quite different... You move me to next level, TQ... Quote
Gertie Posted June 5, 2003 Posted June 5, 2003 not working javascript confirm? I have a button btnWis and in my page_load i try to give him a javascript to ask the user to go on or not (dutch). But it doesn't do a thing? What have i done wrong? btnWis.Attributes.Add("onclick", "return confirm('Bent u zeker dat u deze aanvraag wil verwijderen?');") I've also tried btnWis.Attributes("onclick")="javascript:return confirm('Bent u zeker dat u deze aanvraag wil verwijderen?');" but nothing works. ps: it worked once, but for one reason or another it stopped working? strange!! thx, Greetz Gertie :-\ Quote
zy_abc Posted June 5, 2003 Posted June 5, 2003 Did you use ASP Button or HTML Button? If you could post the sample code we could know where you might have gone wrong. Quote Thanks & Regards, zy_abc
Gertie Posted June 6, 2003 Posted June 6, 2003 I had a validator on it. The requiredfieldvalidator, seems to change that 'onclick' event. So it only does the validate. Now i've turned the validation OF and made a validation in the code behind, to show a "home-made" label with "please fill in..." Et Voila, the confirm started working!! ;) thx Guys beybey Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.