homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Value from ASP/VB in Javascript
Value from ASP/VB in Javascript

 6:09 pm on Nov 15, 2010 (gmt 0)

I'm trying to call a Unique Identifier function (in ASP/VB) in my Javascript function, and the returned value is the same each time. On the other hand, when I call the ASP/VB function from separate Javascript alert boxes, the value is different each time. I would like to get a different value each time, with the function, if possible.

Does anyone know why the value would be the same? Many thanks for any help on this.


Function GetGuid()
Set TypeLib = CreateObject("Scriptlet.TypeLib")
GetGuid = Left(CStr(TypeLib.Guid), 38)
Set TypeLib = Nothing
End Function

The javascript:

function GetGuid_test_f()
alert("strGetGuid_test is...."+strGetGuid_test)




The Javascript that works (gives a different GUID each time)

alert("strGetGuid_test is...."+strGetGuid_test)
alert("strGetGuid_test_b is...."+strGetGuid_test_b)
alert("strGetGuid_test_c is...."+strGetGuid_test_c)



 6:58 pm on Nov 15, 2010 (gmt 0)

The GetGuid method runs at the server. The GetGuid_test_f method runs at the client. The reason the second bit of code works is because you're calling the server side method multiple times, while in the first example you're only calling it once. If you were to view the source of your page in the browser, you would see that your GetGuid_test_f method will have a single hard coded value. As in:

function GetGuid_test_f()

Is the number of times that you need to call GetGuid a fixed amount, or could it vary?


 7:57 pm on Nov 15, 2010 (gmt 0)

The actual application is a "create new div" code, and the function for creating the new div sets a variable equal to the result of the GetGuid (ASP) function (below).

var strObj_GUID = '<%=GetGuid()%>';

Each time a user clicks on the "create new div" button, the same code will be called. So, the number of times is widely variable.
Is the GetGuid function not accessed more than once (as it returns the same result each time)?
Thanks again for your help.


 8:38 pm on Nov 15, 2010 (gmt 0)

Yes, each time the button is clicked the JavaScript (client side) code will execute. The ASP (server side) code, though, would only have been executed once when the page was initially accessed on the server. The output of that initial call was used to populate a value in the client side code, but calling that client side code does not cause the server side code to execute again.

If you need to get the value from ASP code, then you may want to use AJAX to send another request to the server. However, you should evaluate whether you want a solution that will work for users that have JavaScript disabled as well.


 11:20 pm on Nov 15, 2010 (gmt 0)

Many thanks - I think it's a little clearer now.
I decided to append the ASP UUID string with the current date from js, incl milliseconds, to make it unique.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved