473,765 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mixing .NET function into Javascript call doesn't work right... Help

ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when they press "Cancel" they call another ASPX function.

My code now is:

System.Web.Http Context.Current .Response.Write ("<SCRIPT LANGUAGE=""Java Script"">" & vbCrLf)
System.Web.Http Context.Current .Response.Write ("if (confirm('Are you sure you want to delete the user " & UserID & "')) " & DeleteUser(User ID) & "; else " & list_users(ddSi tes.SelectedVal ue) & ";")
System.Web.Http Context.Current .Response.Write ("</SCRIPT>")

which also works as:

Dim strScript As String
strScript = "<script>"
strScript = strScript & "if (confirm('Are you sure you want to delete the user')) " & DeleteUser(User ID) & "; else " & list_users(ddSi tes.SelectedVal ue) & ";"
strScript = strScript & "</script>"
RegisterClientS criptBlock("Cli entScript", strScript)

It works with one pretty important problem. No matter which order I put the DeleteUser function (on Ok or Cancel button)
it still goes to it and Deletes the user. Obviously, this isn't supposed to happen. If they choose the Cancel button, they should just reload the userlist, without the delete taking place.

If I completely remove the DeleteUser function from the call and make both list_user like this:

strScript = strScript & "if (confirm('Are you sure you want to delete the user')) " & list_users(ddSi tes.SelectedVal ue) & "; else " & list_users(ddSi tes.SelectedVal ue) & ";"
Then it ignors the Delete function, like it should and just reloads the datagrid. Then of course, the problem is... it never allows you to delete.
By the way... using {} in my Javascript call doesn't seem to matter....

Help?!

Jul 21 '05 #1
1 5075
Your question is not very clear. You cannot call a server-side function
from client-side javascript code. By the looks of it, you are calling the
server-side DeleteUser function as you construct the string, which is why
the user gets deleted irrespective of what is chosen in the javascript
alert.

It appears that you have a sites dropdownbox, users dropdownbox, and delete
button. Populate your boxes in the page_load subroutine. Set your sites
dropdown autopostback property to true, so that you populate the users
dropdown whenever the sites dropdownbox is changed (the selected item is
changed). Attach the client side check to the onclick handler of the
button.
Private Sub PageLoad(sender As Object, e As System.EventArg s) Handles
Page.Load

If (Not Page.IsPostBack ) Then

'Populate sites dropdown here
'...
End If

'Add onclick handler to delete button
btnDelete.Attri butes.Add("onCl ick", "return confirm('Are you sure you
want to delete this user?')")

End If
Private Sub ddSites_Selecte dIndexChanged(s ender As Object, e As
System.EventArg s) Handles ddSites.Selecte dIndexChanged

'Populate users dropdown here

End Sub
Private Sub btnDelete_Click (sender As Object, e As System.EventArg s) Handles
btnDelete.Click

'Get user ID
Dim userID As Int = Convert.ToInt32 (ddUsers.Select edItem.Value)

'Delete user
'...

End Sub
The code above hasn't been checked, so there's probably some bugs in it, but
it should give you an idea of an alternative approach to the problem.

Hope this helps,

Mun

--
Munsifali Rashid
http://www.munsplace.com/


"cheezebeet le" <an*******@disc ussions.microso ft.com> wrote in message
news:07******** *************** ***********@mic rosoft.com...
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which
when they press "OK" they call this ASPX function, when they press "Cancel"
they call another ASPX function.
My code now is:

System.Web.Http Context.Current .Response.Write ("<SCRIPT LANGUAGE=""Java Script"">" & vbCrLf) System.Web.Http Context.Current .Response.Write ("if (confirm('Are you sure you want to delete the user " & UserID & "')) " & DeleteUser(User ID) & ";
else " & list_users(ddSi tes.SelectedVal ue) & ";") System.Web.Http Context.Current .Response.Write ("</SCRIPT>")

which also works as:

Dim strScript As String
strScript = "<script>"
strScript = strScript & "if (confirm('Are you sure you want to delete the user')) " & DeleteUser(User ID) & "; else " &
list_users(ddSi tes.SelectedVal ue) & ";" strScript = strScript & "</script>"
RegisterClientS criptBlock("Cli entScript", strScript)

It works with one pretty important problem. No matter which order I put the DeleteUser function (on Ok or Cancel button) it still goes to it and Deletes the user. Obviously, this isn't supposed to happen. If they choose the Cancel button, they should just reload the
userlist, without the delete taking place.
If I completely remove the DeleteUser function from the call and make both list_user like this:
strScript = strScript & "if (confirm('Are you sure you want to delete the user')) " & list_users(ddSi tes.SelectedVal ue) & "; else " &
list_users(ddSi tes.SelectedVal ue) & ";"

Then it ignors the Delete function, like it should and just reloads the datagrid. Then of course, the problem is... it never allows you to delete.

By the way... using {} in my Javascript call doesn't seem to matter....

Help?!

Jul 21 '05 #2

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

Similar topics

39
6551
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
1
326
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf) System.Web.HttpContext.Current.Response.Write("if (confirm('Are you sure you want to...
7
2670
by: Ubantu Rococo | last post by:
Hi all, Sorry for this stupid question, but I am having trouble mixing imagecopy etc. with HTML. What I am trying to do is copy an image, and then obtain co-ordinates from a database which will then be drawn on the image (to create a clickable imagemap). The image will then be displayed as part of a webpage. I've included my code snippet below. It doesn't work, and I think I know why - the output on my screen
6
4309
by: D | last post by:
Hello all...I have an issue with one of my java script functions that I'm hoping someone can easily help with. I have a web based application that we use to create/sign up for overtime. When we have holidays we require our employees to sign up in 4 hr increments for the times we post. I'm having trouble creating a time slot that ends @ 12am. 12pm and all other hours work fine for start/end times. however 12am causes problems. My actual...
11
11534
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the function whether i click the link then i tried this (using forms)
3
9281
pbmods
by: pbmods | last post by:
AN INTRODUCTION TO FUNCTION OBJECTS LEVEL: INTERMEDIATE PREREQS: OBJECTS You've seen it before. You're setting up an XMLHttpRequest call, and you need to execute a function when it returns, so you do something like this: http.onreadystatechange = myAwesomeFunction;
7
1540
by: =?Utf-8?B?am9uZWZlcg==?= | last post by:
I'm hoping this is a classic question, but the answer to it would help me with a lot of things. As you can see below, this code will never display the "Getting data...." text in the lblCheck - because it needs to do a round-trip to the server - first. And when it gets back, my other routine will over-write the text as "34 records found" Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
3
7368
by: Jimmy | last post by:
It is also possible for popup window to call function in main window by using the opener property. Will "opener.someFunctionInMain(param1, param2)" in the popup window work? It's possible for main window to call function in the popup window, right? The following is a sample code (close popup window causes to show alert window) which doesn't seems to work. Can anyone see the problem? // main
10
7303
by: evicailieva | last post by:
A have a php scrip where I call a JavaScript function. I don't know why, but it doesn't work. At the beginning, when I was writing the script it was working but now it's not. I don't know wхat to do. Please help me. Here is the php code: function print_rezBilet($rezBilet,$posRezBilet1){ $step=$_SESSION; $max=$_SESSION; $curr= $_SESSION+$step-1 ; if($max<$curr) $curr=$max;
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.