Solved

Change an image in asp.net while stored procedure is running

Posted on 2013-12-18
2
335 Views
Last Modified: 2014-01-02
I have a stored procedure that is run from a single button click on an aspx page. I have the image change at the end when the stored procedure runs successfully. I want to change the image also WHILE the stored procedure is running. The image I want to change to is an animated gif.
    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        btnSubmit.ImageUrl = "~/images/cog.gif";

    try
    {
        System.Data.SqlClient.SqlConnection oConn = new System.Data.SqlClient.SqlConnection();
        System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand();
        oConn.ConnectionString = ConfigurationManager.ConnectionStrings["man_pilotConnectionString"].ConnectionString;
        oConn.Open();
        oCmd.Connection = oConn;
        oCmd.CommandText = "aer_deactivate_recipes";
        oCmd.CommandType = CommandType.StoredProcedure;
        oCmd.Parameters.Add("@user", SqlDbType.VarChar, 25).Value = Label2.Text;
        oCmd.ExecuteNonQuery();
        oConn.Close();

        System.Data.SqlClient.SqlConnection oConn2 = new System.Data.SqlClient.SqlConnection();
        System.Data.SqlClient.SqlCommand oCmd2 = new System.Data.SqlClient.SqlCommand();
        oConn2.ConnectionString = ConfigurationManager.ConnectionStrings["fin_pilotConnectionString"].ConnectionString;
        oConn2.Open();
        oCmd2.Connection = oConn2;
        oCmd2.CommandText = "AER_UPDATE_PART_UOM_CONVERSIONS";
        oCmd2.CommandType = CommandType.StoredProcedure;
        oCmd2.ExecuteNonQuery();
        oConn2.Close();

        btnSubmit.ImageUrl = "~/images/Halo.gif";
        Label1.Text = "Wasn't that easy??";

    }
        
    catch (Exception ex)
        {
            btnSubmit.ImageUrl = "~/images/failure.jpg";
            Label1.Text = "Woops. Something went awry: " + ex.Message;
        }
    }

Open in new window

The image at the end changes successfully when the stored procedure is finished, but it takes several seconds for the sproc to run. I put the image change as the first action on the button click, before the sproc starts. I have also tried putting as the first action under the try block. What am I missing to get this image to change while the stored procedure is running?

Ultimately, I also want to get the page to play a sound when everything is finished. This is an application that is run once per year on January 1st and I try to make it "fun" and "different" every year since they have to work on the 1st.
0
Comment
Question by:Hers2keep
2 Comments
 
LVL 51

Accepted Solution

by:
tedbilly earned 500 total points
Comment Utility
OK, I think there is a misunderstanding about how web pages work.

When the user presses a button, the page request is submitted to the server.  The browser then waits for the server to process the request.  Your code and the stored procedure are executed before any results are sent back to the client.  What you have to understand is that there actually isn't an active streaming connection between the server and browser while the page is being processed on the server.  The browser won't show the page until the server is done processing the page and sends the results back to the browser.

What you are trying to do is not how web pages were designed!

Your results can be achieved but it's really tricky to do using some clever JavaScript and an IMG tag that executes an ASPX page instead of retrieving an image.  Many people don't realize that the src for an IMG tag can actually execute a page on the server.
<img src="http://mysite/mywebpage.aspx" />

Or you can look at using the UpdateProgress control in AJAX.

Sorry but it would take me an hour to write out a detailed example and I don't have time to do it.  I'm a volunteer.  I can point you in the right direction, however you need to find a good example on the web yourself.
0
 

Author Comment

by:Hers2keep
Comment Utility
I found a work-around to achieve almost the same thing as I originally wanted. The only difference was I didn't change the image WHILE the query was running, but only changed it after it finished.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now