How to hide and show a button after executing javascript function

Discussion in 'ASP .Net' started by Mic, Aug 29, 2007.

  1. Mic

    Mic Guest

    Hi,

    How can I hide a button before executing a javascript function and
    make it visible again after execution of the javascript function?

    What I need to do is:

    VB Page_Load:
    1) Hide Button1: Button1.Visible = False
    2) Execute JavaScript (I'm using
    Page.ClientScript.RegisterStartupScript)
    3) Show Button1: Button1.Visible = True

    I am new using these mixed languages and I have not been able to do
    it.

    Thanks
    Mic, Aug 29, 2007
    #1
    1. Advertising

  2. On Aug 30, 12:26 am, Mic <> wrote:
    > Hi,
    >
    > How can I hide a button before executing a javascript function and
    > make it visible again after execution of the javascript function?
    >
    > What I need to do is:
    >
    > VB Page_Load:
    > 1) Hide Button1: Button1.Visible = False
    > 2) Execute JavaScript (I'm using
    > Page.ClientScript.RegisterStartupScript)
    > 3) Show Button1: Button1.Visible = True
    >
    > I am new using these mixed languages and I have not been able to do
    > it.
    >
    > Thanks


    Mic, you have to do 1st and 3rd steps using a javascript after you did
    step #2. RegisterStartupScript does register a client-side script and
    not execute it.
    Alexey Smirnov, Aug 29, 2007
    #2
    1. Advertising

  3. Mic

    Mic Guest

    Hi Alexey,

    What I'm trying to achieve is to print a page when user clicks on a
    button but I don't want this button to get printed with the page.
    I just tried the following; printing is fine but the button is always
    visible and is printed:
    ------------------------------------------
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    Dim ret As Boolean = PrintWithJava()

    End Sub
    ------------------------------------------
    Private Function PrintWithJava() As Boolean

    Dim strScript As String
    strScript = "<script language='javascript'>"
    strScript +=
    "document.getElementById('Button1').style.visibility = 'hidden';"
    strScript += "window.print();"
    strScript +=
    "document.getElementById('Button1').style.visibility = 'visible';"
    strScript += "</script>"

    Page.ClientScript.RegisterStartupScript(GetType(Page),
    "myPrintScript", strScript, False)

    Return True
    End Function
    ------------------------------------------

    Thanks !


    On Aug 29, 6:41 pm, Alexey Smirnov <> wrote:
    > On Aug 30, 12:26 am, Mic <> wrote:
    >
    >
    >
    > > Hi,

    >
    > > How can I hide a button before executing a javascript function and
    > > make it visible again after execution of the javascript function?

    >
    > > What I need to do is:

    >
    > > VB Page_Load:
    > > 1) Hide Button1: Button1.Visible = False
    > > 2) Execute JavaScript (I'm using
    > > Page.ClientScript.RegisterStartupScript)
    > > 3) Show Button1: Button1.Visible = True

    >
    > > I am new using these mixed languages and I have not been able to do
    > > it.

    >
    > > Thanks

    >
    > Mic, you have to do 1st and 3rd steps using a javascript after you did
    > step #2. RegisterStartupScript does register a client-side script and
    > not execute it.
    Mic, Aug 30, 2007
    #3
  4. On Aug 30, 3:54 pm, Mic <> wrote:
    > Hi Alexey,
    >
    > What I'm trying to achieve is to print a page when user clicks on a
    > button but I don't want this button to get printed with the page.
    > I just tried the following; printing is fine but the button is always
    > visible and is printed:
    > ------------------------------------------
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >
    > Dim ret As Boolean = PrintWithJava()
    >
    > End Sub
    > ------------------------------------------
    > Private Function PrintWithJava() As Boolean
    >
    > Dim strScript As String
    > strScript = "<script language='javascript'>"
    > strScript +=
    > "document.getElementById('Button1').style.visibility = 'hidden';"
    > strScript += "window.print();"
    > strScript +=
    > "document.getElementById('Button1').style.visibility = 'visible';"
    > strScript += "</script>"
    >
    > Page.ClientScript.RegisterStartupScript(GetType(Page),
    > "myPrintScript", strScript, False)
    >
    > Return True
    > End Function
    > ------------------------------------------
    >
    > Thanks !
    >
    > On Aug 29, 6:41 pm, Alexey Smirnov <> wrote:
    >
    >
    >
    > > On Aug 30, 12:26 am, Mic <> wrote:

    >
    > > > Hi,

    >
    > > > How can I hide a button before executing a javascript function and
    > > > make it visible again after execution of the javascript function?

    >
    > > > What I need to do is:

    >
    > > > VB Page_Load:
    > > > 1) Hide Button1: Button1.Visible = False
    > > > 2) Execute JavaScript (I'm using
    > > > Page.ClientScript.RegisterStartupScript)
    > > > 3) Show Button1: Button1.Visible = True

    >
    > > > I am new using these mixed languages and I have not been able to do
    > > > it.

    >
    > > > Thanks

    >
    > > Mic, you have to do 1st and 3rd steps using a javascript after you did
    > > step #2. RegisterStartupScript does register a client-side script and
    > > not execute it.- Hide quoted text -

    >
    > - Show quoted text -


    Because, as I wrote, you have to:

    1) RegisterStartupScript
    2) hide on click via js and not in the code-behind

    The PrintWithJava() method in your code does not execute any client-
    side script, ASP.NET cannot do it from the server side.

    I think, you can delete all that code you made and a Button Control
    too.

    Instead, add following

    <input type="button"
    onClick="this.style.visibility='hidden';window.print();this.style.visibility='visible';"
    Value="Print">

    And try, if it works (I didn't test it)
    Alexey Smirnov, Aug 30, 2007
    #4
  5. Mic

    Mic Guest

    Hi Alexey,

    I'm lost here because code gets executed with
    Page.ClientScript.RegisterStartupScript because printing occurs when
    code reaches this line. The name RegisterStartupScript would suggest
    that it should only register the script to be used later somehow but
    it executes the code.

    About your code:

    <input type="button"
    onClick="this.style.visibility='hidden';window.print();this.style.visibility='visible';"
    Value="Print">

    Where do I put it and how do I call it ? I thought the Javascript code
    would get executed with Page.ClientScript.RegisterStartupScript.

    As you can see I'm quite mixed up with this so I really appreciate
    your help.



    On Aug 30, 10:28 am, Alexey Smirnov <> wrote:
    > On Aug 30, 3:54 pm, Mic <> wrote:
    >
    >
    >
    > > Hi Alexey,

    >
    > > What I'm trying to achieve is to print a page when user clicks on a
    > > button but I don't want this button to get printed with the page.
    > > I just tried the following; printing is fine but the button is always
    > > visible and is printed:
    > > ------------------------------------------
    > > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Button1.Click

    >
    > > Dim ret As Boolean = PrintWithJava()

    >
    > > End Sub
    > > ------------------------------------------
    > > Private Function PrintWithJava() As Boolean

    >
    > > Dim strScript As String
    > > strScript = "<script language='javascript'>"
    > > strScript +=
    > > "document.getElementById('Button1').style.visibility = 'hidden';"
    > > strScript += "window.print();"
    > > strScript +=
    > > "document.getElementById('Button1').style.visibility = 'visible';"
    > > strScript += "</script>"

    >
    > > Page.ClientScript.RegisterStartupScript(GetType(Page),
    > > "myPrintScript", strScript, False)

    >
    > > Return True
    > > End Function
    > > ------------------------------------------

    >
    > > Thanks !

    >
    > > On Aug 29, 6:41 pm, Alexey Smirnov <> wrote:

    >
    > > > On Aug 30, 12:26 am, Mic <> wrote:

    >
    > > > > Hi,

    >
    > > > > How can I hide a button before executing a javascript function and
    > > > > make it visible again after execution of the javascript function?

    >
    > > > > What I need to do is:

    >
    > > > > VB Page_Load:
    > > > > 1) Hide Button1: Button1.Visible = False
    > > > > 2) Execute JavaScript (I'm using
    > > > > Page.ClientScript.RegisterStartupScript)
    > > > > 3) Show Button1: Button1.Visible = True

    >
    > > > > I am new using these mixed languages and I have not been able to do
    > > > > it.

    >
    > > > > Thanks

    >
    > > > Mic, you have to do 1st and 3rd steps using a javascript after you did
    > > > step #2. RegisterStartupScript does register a client-side script and
    > > > not execute it.- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Because, as I wrote, you have to:
    >
    > 1) RegisterStartupScript
    > 2) hide on click via js and not in the code-behind
    >
    > The PrintWithJava() method in your code does not execute any client-
    > side script, ASP.NET cannot do it from the server side.
    >
    > I think, you can delete all that code you made and a Button Control
    > too.
    >
    > Instead, add following
    >
    > <input type="button"
    > onClick="this.style.visibility='hidden';window.print();this.style.visibility='visible';"
    > Value="Print">
    >
    > And try, if it works (I didn't test it)
    Mic, Aug 31, 2007
    #5
  6. On Aug 31, 9:07 pm, Mic <> wrote:
    > Hi Alexey,
    >
    > I'm lost here because code gets executed with
    > Page.ClientScript.RegisterStartupScript because printing occurs when
    > code reaches this line. The name RegisterStartupScript would suggest
    > that it should only register the script to be used later somehow but
    > it executes the code.
    >


    Well, maybe I misunderstood you. I'm reading your first post again:
    where do you need a button? Do you want to open the print dialog on a
    button click or when the page is loaded?
    Alexey Smirnov, Aug 31, 2007
    #6
    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. Guadala Harry
    Replies:
    4
    Views:
    1,505
    =?Utf-8?B?aGFyaSBwcmFzYWQ=?=
    Jun 15, 2004
  2. dje
    Replies:
    5
    Views:
    1,698
    =?Utf-8?B?Q2hyaXM=?=
    Dec 2, 2004
  3. Shapper

    Image Button and Show/Hide Panel

    Shapper, Sep 21, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    10,290
    Shapper
    Sep 21, 2005
  4. =?Utf-8?B?Sm9l?=

    Show Details/Hide Details link button

    =?Utf-8?B?Sm9l?=, Mar 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    905
    dkode
    Mar 13, 2006
  5. ll
    Replies:
    2
    Views:
    641
    Thomas 'PointedEars' Lahn
    May 1, 2008
Loading...

Share This Page