ASP.Net using AJAX WPF Service cannot return string to Javascript

jrothlander

New member
Joined
Feb 7, 2012
Messages
4
Programming Experience
10+
I am pretty new to this sort of coding. I am working on a ASP.Net app written mostly in VB.Net. I have extended a login screen to do some initial validations for user accounts. Sort of like when you enter a userid and it tells you that is not a valid id. What I have setup is an AJAX enabled WPF service that hits the DB and validates the user id to see if it is valid. If not, I put up a message that says it is not valid. I first set this up all in VB and it worked fine. Now I am pushing it to use javascript/ajax so it will run without a postback. I am weak in regards to javascript an ajax so I suspect I am missing something simple here.

What I am having trouble with is create a function like...

VB.NET:
if (!IsUserInDB(userid))
{
//display warning that it is an invalid user id.
}
I have a function like...

VB.NET:
function IsUserInDB(userid)
{
    var lgs = new login.loginservice();
    var result = lgs.GetStaffId(userid);
    if (!result)
    {return false;}
    else
    {return true;}
}

I know that you can use a callback function, but that is async process and that will not work for my if structure that calls the functon. So I need to do this without a callback function... I think. But when I do, the VB.Net does not return a string, it returns an object. In vb.Net the String type is an object. In C# I can use a string (not String) and this might work. But in VB.Net it does not. If anyone knows how to use the CLR string and not the vb.net String object, that might fix this. But I do not know.

If I create a callback function I can get the string back that I want. But then the process is async and my if(!IsUserInDB) runs without returning the value and continues to the next line.

So how are you supposed to do something like this? I've been messing around with hidden variables, global variables, and other things to get this to work. But in the end, if I can return the VB.Net string object to the javascript... and convert that back to the string that I need, it would work as is.

But I don't really know what I am doing here. I might be missing something simple.

Any thoughts or suggestions are much appreciated.

Best regards,
Jon
 
Show the warning when the result is ready, from the callback. In the mean time you can show indication of progress, like a "processing..." message.
 
Back
Top