Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Executing client *and* server side script with one call

Reply
Thread Tools

Executing client *and* server side script with one call

 
 
Burak
Guest
Posts: n/a
 
      06-02-2004
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
 
Reply With Quote
 
 
 
 
Robert Koritnik
Guest
Posts: n/a
 
      06-03-2004
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.

--
RobertK
{ Clever? No just smart. }


"Burak" <> wrote in message
news: om...
> 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



 
Reply With Quote
 
 
 
 
Burak Gunay
Guest
Posts: n/a
 
      06-03-2004
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,m enubar=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,m enubar=yes,';
<br>"
script +=
"sOption+='scrollbars=yes,width=750,height=600,lef t=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!
 
Reply With Quote
 
Robert Koritnik
Guest
Posts: n/a
 
      06-03-2004
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.

--
RobertK
{ Clever? No just smart. }

"Burak Gunay" <> wrote in message
news:...
> 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,m enubar=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,m enubar=yes,';
> <br>"
> script +=
> "sOption+='scrollbars=yes,width=750,height=600,lef t=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!



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Client side script after client side validation with asp.net 2.0 Boss302 ASP .Net 0 11-21-2006 08:43 AM
Server-side script with input parameter from Client-side script Magnus Blomberg ASP .Net 3 04-14-2005 12:21 PM
Problem in executing a script on the server side ! Script found but nothing executed ! Cédric Rossé ASP .Net 1 11-09-2004 09:43 AM
Run Server-side Function *immediately after* executing client-side JavaScript. Guadala Harry ASP .Net 4 06-15-2004 07:04 AM
Call server side code from client side Borr ASP .Net 2 11-10-2003 02:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57