Using Client-Side scripting

D

Dave

I have a vb routine below where I'm trying to capture a name from a
javascript prompt box. My application is inline VB on Visual Studio 2003.

The prompt box does display, but when I type a string and hit OK or Cancel,
the value 'ret' which I want to hold the value of the string, is always
empty. And the status bar always says "Done but with errors on page."

If I use a simpler control like alert or confirm, I get no problems.

Can someone point out my error, either conceptual, syntactical, or whatever?

Thanks,

Dave


Sub GetUsername()
Dim ret as String 'This is the value I want to capture
Dim msg As String = "Type your name"
Dim sKey As String = "sKey"
Dim alertScript As String = "<script language=JavaScript runat=server>
'" & ret & "' = prompt('" & msg & "'); <" & "/script>"

RegisterClientScriptBlock(sKey, alertScript)
End Sub
 
C

Cor Ligthert

Dave,

You write in your JavaScript "Runat Server" what will not work with an
alert.

As well has the alert no messagebox part, it is only an "Alert".

Standard is for what you want to use a loginform or otherwise a normal
textbox.

I thought that I had seen that using VBScript somebody could use a kind of
DHTML "messagebox". However I don't remember me anymore where, maybe you can
look for yourself on Google or MSDE for this. I am myself not interested in
that and keep it to the more standard way of doing this.

However maybe somebody knows that DHTML "messagebox" method.

I hope this gives any ideas anyhow.

Cor
 
D

Dave

First of all, thanks for your response, Cor.

I have been wrestling with this for a while, looking at some interesting
posts via Google, and I have succeeded in getting the desired value into a
javascript variable thus:

In the html:
<input type="hidden" name="HiddenUserName" id="HiddenUserName" />

In the vb routine
Sub GetUsername()
Dim ret as String 'This is the value I want to capture
Dim msg As String = "Type your name"
Dim sKey As String = "sKey"
Dim alertScript As String = "<script language=JavaScript> var ret,
HiddenUID; ret = prompt('" & msg & "'); var HiddenUID =
document.getElementbyId('HiddenUserName'); HiddenUID = ret; <" & "/script>"

RegisterClientScriptBlock(sKey, alertScript)
End Sub

The value for ret is trapped in the RegisterClientScriptBlock call, but I
don't know how to get it into the vb side (server-side). I get an error
saying 'document.getElementbyId is not a supported.

Can anyone tell me how to pass the value for ret from the client to the
server? I would need a pretty explicit answer.

Thanks,

David
 
C

Cor Ligthert

Dave,

As I wrote had seen this as well, however did not know anymore where.

As far as I remember me, (it is a while ago I did that) is a simple way to
transport data from client to serverer is using a hidden textbox where you
place (using JavaScript) the information in.

Maybe I try your messagebox, however don't promish that

I hope this helps anyway.

Cor
 
C

Cor Ligthert

Dave,

I think that in this way it can work, however there should be better
methods.

\\\ a textbox and a button on a form
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim str As String
If Not IsPostBack Then
TextBox1.ForeColor = Color.White
TextBox1.BorderStyle = BorderStyle.None
Dim alertScript As String = _
"<script language=JavaScript>document.all.item('TextBox1').value
" & _
" = prompt('Give me text','My name is nobody'); </script>"
RegisterStartupScript("Startup", alertScript)
Else
str = TextBox1.Text
End If
End Sub
///
I hope this helps a little bit?

Cor
 
D

Dave

Cor, thanks very much. I need to buff this up a little, but I think it
will work. That document.all.item was they key for me.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top