• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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.
0
Term56
Asked:
Term56
  • 6
  • 5
1 Solution
 
bgloddeCommented:
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


0
 
Term56Author Commented:
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).
0
 
bgloddeCommented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Term56Author Commented:
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
0
 
bgloddeCommented:
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

0
 
Term56Author Commented:
nope, still not working.

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

0
 
bgloddeCommented:
Can you post a bit more of your page behind code please?
0
 
Term56Author Commented:
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
0
 
bgloddeCommented:
Let's try this variation:

<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>"
        RegisterStartupScript("disabler", js)

        Bind_Data()
End Sub

The "RegisterStartupScript" method emits the script just before the closing tag of the Page object's <form runat=server> element.
Hopefully this will do the trick, otherwise, I think we're going to need to post the whole page behind so the full picture is there ~
0
 
bgloddeCommented:
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.
0
 
Term56Author Commented:
ok bglodde, I do appreciate all the effort you put into it. Let me post as much code as possible relevant to it
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now