showmodaldialog issues

L

luna

im playing around with showmodeldialog, and the child window isnt returning
the variable to the parent

in the parent i have

Button2.Attributes.Add("onclick", "var strReturn;
strReturn=window.showModalDialog('test.aspx',null,'status:no;dialogWidth:370px;dialogHeight:220px;dialogHide:true;help:no;scroll:no');if
(strReturn != null) document.getElementById('Label45').value=strReturn;")


child window has

Button1.Attributes.Add("onclick", "window.returnValue =
document.getElementById('TextBox1').value; window.close();")

if im correct - it should pass contents of TextBox1 to the parent and the
parent should show Label45 as the passed back variable - except it does
nothing ?

i feel like im on the right track somewhere!

cheers

Mark
 
L

luna

im not sure where


both attributes.add statements are on page load,

child has <base target="_self"> between <head> </head>

otherwise another window pops up

am i correct in saying the variable should appear on the parent once ive
clicked the button on the child ?
 
E

Eliyahu Goldin

What is the type of Label45?

If it is an asp:Label, it renders as a <span>. To change its text on client
side you should assign to

document.getElementById('Label45').innerText

Eliyahu
 
L

luna

that did the trick thanks,

BUT

its sending the string back, the label changes, then it quickly changes back
to what it was

(blank) - what causes this ?
 
E

Eliyahu Goldin

Likely a postback takes place. The server code knows nothing about the new
value and restores the label to previous blank one.

If you need to persist the value between the postbacks, you should pass it
on to the server in a hidden <input> control. Alternatively you can you a
textbox instead of a label.

Eliyahu
 
L

luna

works great with a textbox, thanks , how come it doesnt work with labels ?
is it the innerText fucntion causing the issue? i can work with the textbox
tho i think
 
L

Laurent Bugnion

Hi,

Eliyahu said:
What is the type of Label45?

If it is an asp:Label, it renders as a <span>. To change its text on client
side you should assign to

document.getElementById('Label45').innerText

Eliyahu

Why not rather use a standard attribute, with:

document.getElementById( "Label45" ).firstChild.nodeValue

This way, the code will work in both IE and Firefox (about 15% of market
share ;-)

Laurent
 
L

luna

Laurent Bugnion said:
Hi,



Why not rather use a standard attribute, with:

document.getElementById( "Label45" ).firstChild.nodeValue

This way, the code will work in both IE and Firefox (about 15% of market
share ;-)

that work on postback tho ?, browser isnt important, as its an internal app,
all users use ie6

cheers

mark
 
L

Laurent Bugnion

Hi,
that work on postback tho ?,

The code I gave you is pure client-side. Client-side JavaScript doesn't
have a mechanism to preserve a "control"'s state over a postback.
Setting "innerText" also doesn't, and additionally it doesn't work in
Firefox.
browser isnt important, as its an internal app,
all users use ie6

That's not an excuse for coding against standards in my opinion.
cheers

mark

HTH
Laurent
 
E

Eliyahu Goldin

The short answer is that the Label control is not designed for passing
values back to server whereas the Textbox is.

Eliyahu
 

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,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top