Executing client *and* server side script with one call

Discussion in 'ASP .Net Web Controls' started by Burak, Jun 2, 2004.

  1. Burak

    Burak Guest

    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
    Burak, Jun 2, 2004
    #1
    1. Advertising

  2. 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:...
    > 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
    Robert Koritnik, Jun 3, 2004
    #2
    1. Advertising

  3. Burak

    Burak Gunay Guest

    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!
    Burak Gunay, Jun 3, 2004
    #3
  4. 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,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!
    Robert Koritnik, Jun 3, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Borr
    Replies:
    2
    Views:
    6,218
    Alvin Bruney
    Nov 10, 2003
  2. Guadala Harry
    Replies:
    4
    Views:
    1,493
    =?Utf-8?B?aGFyaSBwcmFzYWQ=?=
    Jun 15, 2004
  3. Cédric Rossé
    Replies:
    1
    Views:
    515
    Cédric Rossé
    Nov 9, 2004
  4. Magnus Blomberg
    Replies:
    3
    Views:
    694
    Magnus Blomberg
    Apr 14, 2005
  5. Boss302
    Replies:
    0
    Views:
    1,007
    Boss302
    Nov 21, 2006
Loading...

Share This Page