Link to home
Start Free TrialLog in
Avatar of Term56
Term56

asked on

need help disabling a client side button before the server side fires

I have an app that takes variables, passes them to a crystal report, and then exports the end result to a pdf.

I was curious if anyone could tell me if there was a way to fire the server side, but disable a button, or say it is processing on the client side before the server side actually fires.

<asp:button id="Button1" runat="server" Text="Export To PDF"></asp:button>

this is the button. Problem is, if I try to disable the button server side, it doesnt refresh until it already delivers the pdf.

I am assuming I need to use clientside, but dont know how to using javascript. I dont know if it is possible, but perhaps have javascript that disables the button, and somehow causes a postback, but I need

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Bind_Data()
End Sub

server side to fire.
Avatar of bglodde
bglodde
Flag of United States of America image

From what I undertand so far; try calling/inserting a client side script to disable the button from the server side (assuming .net 2.0):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim js As String = "document.forms[0].myButton.enabled = false;"
    ClientScript.RegisterClientScriptBlock(Me.GetType(), "disable", js, true)

    Bind_Data()
End Sub


Avatar of Term56
Term56

ASKER

I'll try it when I get to work. actually it is .net 1.1. but you are basically correct, I need some way to cause a client side effect before the post, as it can take 30-45 seconds to generate the report(lots of data is being parsed in the crystal report).
If you're using the 1.1 Framework, you won't find a ClientScript object. Instead:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim js As String = "document.forms[0].myButton.enabled = false;"
    RegisterClientScriptBlock("myFunction", js)

    Bind_Data()
End Sub
Avatar of Term56

ASKER

tried using mybutton and button1 and neither work.

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim js As String = "document.forms[0].button1.enabled = false;"
        RegisterClientScriptBlock("myFunction", js)
        Bind_Data()
    End Sub
If your button is set to submit, that will be an issue. I also forgot to add the tags to the script. In 2.0, a boolean arg outputs them for you. In < 2.0, you have to insert them yourself.

<asp:Button ID="myButton" runat="server" Text="Export To PDF" />

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles myButton.Click
        Dim js As String = "<script language=javascript>document.forms[0].myButton.enabled = false;</script>"
        RegisterClientScriptBlock("disabler", js)

        Bind_Data()
End Sub

Avatar of Term56

ASKER

nope, still not working.

yeah, unfortunately it is a submit, i knew i'd run into trouble.

Can you post a bit more of your page behind code please?
Avatar of Term56

ASKER

sure

this is the Bind_data()

Private Sub Bind_Data()
        Dim strtest As New WEBTr_Full_Day_Report_v15
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table
        Dim TableCounter
        'Passes LogOn information to the report.
        With crConnectionInfo
            .ServerName = "FMSATURN"
            .DatabaseName = "BILLINGS"
            .UserID = ""
            .Password = ""
        End With
        CrTables = strtest.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next
        'Sets the parameters
        If txtStart.Text <> "" Then
            strtest.SetParameterValue("@StartDate", txtStart.Text)
        Else
            strtest.SetParameterValue("@StartDate", " ")
        End If
        If txtEnd.Text <> "" Then
            strtest.SetParameterValue("@EndDate", txtEnd.Text)
        Else
            strtest.SetParameterValue("@EndDate", " ")
        End If
        strtest.SetParameterValue("@Resources", GetResources)
        strtest.SetParameterValue("@ResDept", GetDepartments)
        strtest.SetParameterValue("@MyFlag", ddFlag.SelectedValue)
        Dim oStream As New MemoryStream ' // using System.IO
        oStream = strtest.ExportToStream(ExportFormatType.PortableDocFormat)
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/pdf"
        Response.BinaryWrite(oStream.ToArray())
        Response.End()
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of bglodde
bglodde
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The only way to properly answer the question is with enough relevant information. I have taken a few runs at it, but if the suggestions above have not worked, we would need to see or understand more of the source code to give a solution.
Avatar of Term56

ASKER

ok bglodde, I do appreciate all the effort you put into it. Let me post as much code as possible relevant to it