Forums
This topic is locked
GUID in ASP to define form variable & pass in URL
Posted 30 Jan 2004 21:33:43
1
has voted
30 Jan 2004 21:33:43 Erik Piisila posted:
I am using the following code in asp to define a unique and unpredictable record ID in Access.<%
'GENERATE UNIQUE ID
Function genguid()
Dim Guid
guid = server.createobject("scriptlet.typelib"

guid=Left(guid,instr(guid,"}"

genguid=guid
genguid= replace(guid, "}", ""

genguid= replace(genguid, "{", ""

genguid= replace(genguid, "-", ""

genguid= replace(genguid, "'", ""

Set guid=nothing
end function
%>
<% Dim strIDFinal
strIDFinal = genguid
strIDFinal = strIDFinal
%>
I want to use strIDFinal to define a hidden field and I also use strIDFinal in the redirect url after record insertion.
MM_editRedirectUrl = "/greetings/mail_greeting_c.asp?messageID=" & strIDFinal & ""
The problem is that GUID is generating two separate IDs for the hidden field and the url
both use the same string variable: strIDFinal
Any help would be appreciated.
thanks <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replies
Replied 04 Feb 2004 15:09:56
04 Feb 2004 15:09:56 Erik Piisila replied:
Well no one responded, so I went elsewhere for assistance. But5, I'll post the solution for anyone else who might be curious.
This is what ended up working for me from your help.
<%
Dim xGUID
xGUID = ""
Call genguid(xGUID)
' Now it is in a local variable (xGUID) and can be used many times
Response.Write(xGUID) ' to test output
%>
<%
'GENERATE UNIQUE ID
Function genguid(xGUID)
Dim Guid
guid = server.createobject("scriptlet.typelib"
.guid
guid=Left(guid,instr(guid,"}"
)
xGUID=guid
Set guid=nothing
xGUID= replace(xGUID, "}", ""
xGUID= replace(xGUID, "{", ""
xGUID= replace(xGUID, "-", ""
xGUID= replace(xGUID, "'", ""
End function
%>
I defined my form variable as:
MessageID = <%= (xGUID) %>
My redirect url was:
MM_editRedirectUrl = "/greetings/mail_greeting_c.asp?messageID=" & CStr(Request.form("MessageID"
) & ""
The problem was in the redirect URL.
If I tried:
MM_editRedirectUrl = "/greetings/mail_greeting_c.asp?messageID=" & (xGUID) & ""
My ID in the URL turned out to be different than my form variable.
This is what ended up working for me from your help.
<%
Dim xGUID
xGUID = ""
Call genguid(xGUID)
' Now it is in a local variable (xGUID) and can be used many times
Response.Write(xGUID) ' to test output
%>
<%
'GENERATE UNIQUE ID
Function genguid(xGUID)
Dim Guid
guid = server.createobject("scriptlet.typelib"

guid=Left(guid,instr(guid,"}"

xGUID=guid
Set guid=nothing
xGUID= replace(xGUID, "}", ""

xGUID= replace(xGUID, "{", ""

xGUID= replace(xGUID, "-", ""

xGUID= replace(xGUID, "'", ""

End function
%>
I defined my form variable as:
MessageID = <%= (xGUID) %>
My redirect url was:
MM_editRedirectUrl = "/greetings/mail_greeting_c.asp?messageID=" & CStr(Request.form("MessageID"

The problem was in the redirect URL.
If I tried:
MM_editRedirectUrl = "/greetings/mail_greeting_c.asp?messageID=" & (xGUID) & ""
My ID in the URL turned out to be different than my form variable.