Assign value to textbox via Java script in VB

S

Sergei

Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm = window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname') didn't
work

Thanks for your response.
 
E

Eliyahu Goldin

What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu
 
S

Sergei

It is ASP.Net VB project.

I have got main form.
It opens modal seacrh form. After a user makes a selection it should return
SelectedID to the main form and reload it
My problem is that I can pass object to the modal search form and get values
back but I don't know how to get values from the object in JavaScript in VB
and reload the form.

Thanks

Eliyahu Goldin said:
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Sergei said:
Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm = window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname') didn't
work

Thanks for your response.
 
E

Eliyahu Goldin

Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if you are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just use
server code, like TextBox1.Value = myParam. What do you need javascript for
then?

Eliyahu

Eliyahu Goldin said:
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Sergei said:
Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm = window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname') didn't
work

Thanks for your response.
 
S

Sergei

Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to the
TextBox on the main form.
It gives error object is required

Thanks

Eliyahu Goldin said:
Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

Eliyahu Goldin said:
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Sergei said:
Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm = window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname')
didn't
work

Thanks for your response.
 
E

Eliyahu Goldin

You do it in javascript. Usually hidden text inputs are used to pass values
from client to server.

document.getElementById("myHiddenInput").value=myParam

Eliyahu

Sergei said:
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to the
TextBox on the main form.
It gives error object is required

Thanks

Eliyahu Goldin said:
Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

Eliyahu Goldin said:
What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Hi,

I am displaying modal dialog and passing values from the main form to the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm =
window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname')
didn't
work

Thanks for your response.
 
S

Sergei

Eliyahu,


I have got this code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var myObject = new Object(); " & vbCrLf
strResponse = strResponse & "myObject.guid = '" & strGuid & "'; " & vbCrLf
strResponse = strResponse & "myObject.id = 0; " & vbCrLf
strResponse = strResponse & "// The object myObject is sent to the modal
window. " & vbCrLf
strResponse = strResponse & "var answer =
window.showModalDialog('datagridHyperLink.aspx', myObject,
'dialogHeight:300px; dialogLeft:200px;'); " & vbCrLf
strResponse = strResponse & "document.getElementById('myHiddenInput').value=
myObject.id; " & vbCrLf
strResponse = strResponse & "window.alert(myObject.guid); " & vbCrLf
strResponse = strResponse & "window.alert(myObject.id); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

End Sub

I have got error again

document.getElementById(...) is null or not an object

Thanks again



Eliyahu Goldin said:
You do it in javascript. Usually hidden text inputs are used to pass
values
from client to server.

document.getElementById("myHiddenInput").value=myParam

Eliyahu

Sergei said:
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to the
TextBox on the main form.
It gives error object is required

Thanks

Eliyahu Goldin said:
Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if
you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just
use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Hi,

I am displaying modal dialog and passing values from the main form
to
the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives
error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm =
window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script
but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname')
didn't
work

Thanks for your response.
 
E

Eliyahu Goldin

I guess the problem is in the way how you sending javascript to client.
Likely, the DHTML object model of your page hasn't been built at this stage,
that's why none of the HTML elements can be found. Why do you need to emit
the javascript in the Response? Why not to put it inside your .aspx page in
the <head> section? BTW, you probably meant

document.getElementById('myHiddenInput').value=answer;

Eliyahu

Sergei said:
Eliyahu,


I have got this code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var myObject = new Object(); " & vbCrLf
strResponse = strResponse & "myObject.guid = '" & strGuid & "'; " & vbCrLf
strResponse = strResponse & "myObject.id = 0; " & vbCrLf
strResponse = strResponse & "// The object myObject is sent to the modal
window. " & vbCrLf
strResponse = strResponse & "var answer =
window.showModalDialog('datagridHyperLink.aspx', myObject,
'dialogHeight:300px; dialogLeft:200px;'); " & vbCrLf
strResponse = strResponse & "document.getElementById('myHiddenInput').value=
myObject.id; " & vbCrLf
strResponse = strResponse & "window.alert(myObject.guid); " & vbCrLf
strResponse = strResponse & "window.alert(myObject.id); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

End Sub

I have got error again

document.getElementById(...) is null or not an object

Thanks again



Eliyahu Goldin said:
You do it in javascript. Usually hidden text inputs are used to pass
values
from client to server.

document.getElementById("myHiddenInput").value=myParam

Eliyahu

Sergei said:
Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript to the
TextBox on the main form.
It gives error object is required

Thanks

Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if
you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just
use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Hi,

I am displaying modal dialog and passing values from the main form
to
the
modal dialog and back.
It works fine but if I used the following syntax on Page_Load(just for
testing) in VB to assign value form the object to text Box it gives
error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm =
window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script
but I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname')
didn't
work

Thanks for your response.
 
S

Sergei

Found the solution - added smartnavgation="true" and it started working.
I used RegisterStartupScript method
Thanks


Eliyahu Goldin said:
I guess the problem is in the way how you sending javascript to client.
Likely, the DHTML object model of your page hasn't been built at this
stage,
that's why none of the HTML elements can be found. Why do you need to
emit
the javascript in the Response? Why not to put it inside your .aspx page
in
the <head> section? BTW, you probably meant

document.getElementById('myHiddenInput').value=answer;

Eliyahu

Sergei said:
Eliyahu,


I have got this code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" & vbCrLf
strResponse = strResponse & "var myObject = new Object(); " & vbCrLf
strResponse = strResponse & "myObject.guid = '" & strGuid & "'; " &
vbCrLf
strResponse = strResponse & "myObject.id = 0; " & vbCrLf
strResponse = strResponse & "// The object myObject is sent to the modal
window. " & vbCrLf
strResponse = strResponse & "var answer =
window.showModalDialog('datagridHyperLink.aspx', myObject,
'dialogHeight:300px; dialogLeft:200px;'); " & vbCrLf
strResponse = strResponse & "document.getElementById('myHiddenInput').value=
myObject.id; " & vbCrLf
strResponse = strResponse & "window.alert(myObject.guid); " & vbCrLf
strResponse = strResponse & "window.alert(myObject.id); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

End Sub

I have got error again

document.getElementById(...) is null or not an object

Thanks again



Eliyahu Goldin said:
You do it in javascript. Usually hidden text inputs are used to pass
values
from client to server.

document.getElementById("myHiddenInput").value=myParam

Eliyahu

Yes, I pass an object as the second parameter.
But I don't know how to assign a value from the object in JavaScript
to
the
TextBox on the main form.
It gives error object is required

Thanks

Just read your message second time.

How do you pass values to the modal dialog? What I wrote was good if
you
are
passing parameters in the second parameter of showModalDialog call.
Otherwise, if you can access the values on server side, you can just
use
server code, like TextBox1.Value = myParam. What do you need javascript
for
then?

Eliyahu

What do you need VB for? Why can't you do everything on the client in
javascript in <body ... onload=...> event?

Eliyahu

Hi,

I am displaying modal dialog and passing values from the main
form
to
the
modal dialog and back.
It works fine but if I used the following syntax on
Page_Load(just
for
testing) in VB to assign value form the object to text Box it gives
error
'Object required'
Dim strResponse As String
strResponse = strResponse & "<script language=""JavaScript"">" &
vbCrLf
strResponse = strResponse & "var aForm; " & vbCrLf
'Error is on the page- Object required
strResponse = strResponse & "aForm =
window.document.body.all[""TextBox1""];
" & vbCrLf
strResponse = strResponse & "window.alert(aForm); " & vbCrLf
strResponse = strResponse & "</script>" & vbCrLf
Response.Write(strResponse)

I want to assign a value from an object to TextBox in Java script
but
I
don't know how to refer to TextBox on page.
Is it - window.document.forms('formname').elements('elementname')
didn't
work

Thanks for your response.
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top