Executing client *and* server side script with one call

B

Burak

Hello,

Is it possible to have a button execute code on the
server and then on the client? After I click a server side asp button,
I would like to make some other buttons invisible on the code behind
and then execute a javascript function on the client side.

Do you know any example of this?

Thank you,

Burak
 
R

Robert Koritnik

Normally you have to use some javascript variable to do this. On the server
event you must set its value and put an onload on body element, that checks
that value and eecutes it... That's the way I've done it once... Not so
smart, but works fine. But you must be really careful with onload event or
immediate javascript executions because you might crash IE. Looks like for
no reason, because it crashes quite randomly, but in the end it's because of
this.
 
B

Burak Gunay

Hello,

Here is the client script I want to execute. It
basically serves to make a page "printer friendly".

function PrintThisPage()
{
var
sOption="toolbar=yes,location=no,directories=yes,menubar=yes,";

sOption+="scrollbars=yes,width=750,height=600,left=100,top=25";

var sWinHTML =
document.getElementById('contentstart').innerHTML;

var winprint=window.open("","_top",sOption);
winprint.document.open();
winprint.document.write('<html><LINK
href=/eggheadcafe.css rel=Stylesheet><body>');
winprint.document.write(sWinHTML);
winprint.document.write('</body></html>');
winprint.document.close();
winprint.focus();
}

I created an image button as follows

<asp:imagebutton id="imgPrint" runat="server"
ImageUrl="images/b_print_friend.gif"></asp:imagebutton>

and my server side code is

Private Sub imgPrint_Click(ByVal sender As Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles
imgPrint.Click
imgBack4.Visible = False
imgSubmit.Visible = False
imgSave5.Visible = False
imgPrint.Visible = False

Dim script As String
script += " script += "function PrintThisPage() <br> "
script += "{ <br>"
script += "var
sOption='toolbar=yes,location=no,directories=yes,menubar=yes,';
<br>"
script +=
"sOption+='scrollbars=yes,width=750,height=600,left=100,top=25';
<br>"
script += "var sWinHTML =
document.getElementById('contentstart').innerHTML;
<br>"
script += "var
winprint=window.open('','_top',sOption); <br>"
script += "winprint.document.open(); <br>"
script +=
"winprint.document.write('<html><LINK
href=/eggheadcafe.css rel=Stylesheet><body>'); <br>"
script += "winprint.document.write(sWinHTML);
<br>"
script +=
"winprint.document.write('</body></html>'); <br> "
script += "winprint.document.close(); <br> "
script += "winprint.focus(); <br>"
script += " } <br> "
script += "</script>"

If Not
IsClientScriptBlockRegistered("PrintThisPage") Then
RegisterClientScriptBlock("PrintThisPage",
script)
End If

End Sub


but nothing is happening on the client side. Do I have
to do something else to execute this script?

Would appreciate your help.

Thank you,

Burak




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
R

Robert Koritnik

put onLoad attribute inside BODY element (be careful that it will be client)
that executes javascript that checks for your javascript function and if it
exists execute it. Or you can have this function on your page all the time
and just register some javasrcipt variable value and on load checks the
value of this variable and if tru call your function.
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top