Solved

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

Posted on 2013-12-18
2
351 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:Carla Romere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 500 total points
ID: 39728537
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:Carla Romere
ID: 39751758
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

626 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