homepage Welcome to WebmasterWorld Guest from 54.166.84.82
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
buck1107

10+ Year Member



 
Msg#: 4230627 posted 6:09 pm on Nov 15, 2010 (gmt 0)

Hi,
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.

The ASP/VB:


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




The javascript:


<script>
function GetGuid_test_f()
{
strGetGuid_test='<%=GetGuid()%>'
//strGetGuid_test='<%=strGetGuid_test_b%>'
alert("strGetGuid_test is...."+strGetGuid_test)
}

GetGuid_test_f()

GetGuid_test_f()

GetGuid_test_f()
</script>





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


strGetGuid_test='<%'=GetGuid()%>'
alert("strGetGuid_test is...."+strGetGuid_test)
strGetGuid_test_b='<%'=GetGuid()%>'
alert("strGetGuid_test_b is...."+strGetGuid_test_b)
strGetGuid_test_c='<%'=GetGuid()%>'
alert("strGetGuid_test_c is...."+strGetGuid_test_c)

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4230627 posted 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()
{
strGetGuid_test='12345678901234567890123456789012345678';


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

buck1107

10+ Year Member



 
Msg#: 4230627 posted 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.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4230627 posted 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.

buck1107

10+ Year Member



 
Msg#: 4230627 posted 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