Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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]

Posted

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

Posted

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>

Posted

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?

Posted
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...
  • 1 month later...
Posted

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

:-\

Posted
Did you use ASP Button or HTML Button? If you could post the sample code we could know where you might have gone wrong.

Thanks & Regards,

zy_abc

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...