Kioko Kiaza
Kioko Kiaza

Reputation: 1398

Change UpdateProgress text on button click

I have this but it´s not working... did I miss something?

I need to change the text withing UpdateProgess on button click for example.

This is my ascx:

<asp:UpdateProgress ID="UpdateProgress2" runat="server"  AssociatedUpdatePanelID="upFormulario">
    <ProgressTemplate>
        <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
            <%--<span id="lblInfo" style="border-width: 0px; position: fixed; padding: 50px; background-color: #FFFFFF; font-size: 36px; left: 40%; top: 40%;">Loading...</span>--%>
            <asp:Label id="lblInfo" Text="..." runat="server" style="border-width: 0px; position: fixed; padding: 50px; background-color: #FFFFFF; font-size: 36px; left: 40%; top: 40%;" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>

<asp:UpdatePanel ID="upFormulario" runat="server">
...
<table width="100%" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <td width="100%" align="right" nowrap="nowrap">   
        <asp:Button runat="server" Text="Next" ID="btnSave" OnClick="cmdSaveDraft_Click" class="ms-ButtonHeightWidth" />
      </td> 
     </tr> 
  </tbody>
</table>
...
</asp:UpdatePanel>

This my code on ascx.cs

protected void cmdSaveDraft_Click(object sender, EventArgs e)
{
    Label progressMessageLabel = this.UpdateProgress2.FindControl("lblInfo") as Label;
    if (progressMessageLabel != null)
    {
        progressMessageLabel.Text = "Saving...";
    }
    lblAccion = "Loading...";

    int iControl = this.ValidateCtrl();
    if (iControl == 1) 
    {
        return;
    }
}

thanks!

Upvotes: 0

Views: 2329

Answers (3)

Gusman
Gusman

Reputation: 15151

Your UpdateProgress is outside the UpdatePanel but your button is inside the update panel.

When you use an update panel, all the controls inside the update panel will work in ajax, they will not do real post but ajax request. In that case, only the controls inside the update panel can be updated from events fired from controls inside the update panel.

Resuming, if you want it to work add the update progress control inside the update panel and it will work.

Upvotes: 1

silviagreen
silviagreen

Reputation: 1729

Maybe this answer can help:

public void bw_Convert_DoWork(object sender, DoWorkEventArgs e)
{           
    e.Result = e.Argument;
    for (int i = 0; i <  fTable.Rows.Count; i++)
    {
        try
        {
            SqlCommand cmd = new SqlCommand("INSERT INTO TBL_CDR_ANALYZER (LNG_UPLOAD_ID, DAT_START, LNG_DURATION, INT_DIRECTION, INT_CALL_DATA_TYPE, \n" +
                "TXT_TARGET_NUMBER, TXT_OTHER_PARTY_NUMBER, TXT_TARGET_IMSI, TXT_TARGET_IMEI, TXT_TARGET_CELL_ID, TXT_ROAMING_NETWORK_COMPANY_NAME) VALUES \n" +
                "(@UPLOAD_ID, @START_DATE, @DURATION, @DIRECTION, @CALL_TYPE, @TARGET_NUMBER, @OTHER_PARTY_NUMBER, @IMSI, @IMEI, @CELL_ID, @ROAMING_NAME)", sqlCon);
            cmd.Parameters.Add("@UPLOAD_ID", SqlDbType.Int).Value = 1;
            cmd.Parameters.Add("@START_DATE", SqlDbType.DateTime).Value = fTable.Rows[i]["CallDate"];
            cmd.Parameters.Add("@DURATION", SqlDbType.Int).Value = fTable.Rows[i]["CallDuration"];
            cmd.Parameters.Add("@DIRECTION", SqlDbType.Int).Value = GetCallDirection(fTable.Rows[i]["CallDirection"].ToString());
            cmd.Parameters.Add("@CALL_TYPE", SqlDbType.Int).Value = GetCallType(fTable.Rows[i]["CallType"].ToString());
            cmd.Parameters.Add("@TARGET_NUMBER", SqlDbType.VarChar, 25).Value = fTable.Rows[i]["TargetNo"];
            cmd.Parameters.Add("@OTHER_PARTY_NUMBER", SqlDbType.VarChar, 25).Value = fTable.Rows[i]["OtherPartyNo"];
            cmd.Parameters.Add("@IMSI", SqlDbType.VarChar, 50).Value = fTable.Rows[i]["IMSI"];
            cmd.Parameters.Add("@IMEI", SqlDbType.VarChar, 50).Value = fTable.Rows[i]["IMEI"];
            cmd.Parameters.Add("@CELL_ID", SqlDbType.VarChar, 50).Value = fTable.Rows[i]["CellID"];
            cmd.Parameters.Add("@ROAMING_NAME", SqlDbType.NVarChar, 255).Value = fTable.Rows[i]["RoamingCompany"];
            sqlCon.Open();
            cmd.ExecuteNonQuery();
            sqlCon.Close();
        }
        catch (SqlException ex)
        {

        }
        finally
        {
            sqlCon.Close();
        }
        bw_Convert.ReportProgress((100 * i) / fTable.Rows.Count);  
      Label1.Invoke((MethodInvoker)delegate {
        Label1.Text = i.ToString() + "Files Converted";});                 
    }    
}

Upvotes: 0

Baaleos
Baaleos

Reputation: 1825

If the button being clicked has Post enabled then I would have thought the label would reflect the text changes on the next refresh of the page. (The button's click code gets executed on the server, not client. So it requires the page load to show the new state of the label)

If you want to have the label text change, without a refresh, you need to use Javascript.

string script = "<script type=\"text/javascript\"> document.getElementById("LABEL").text = 'Loading...'; </script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", script);

I have not tested this, but theoretically it should allow you to change the value of the label, without having to post the page. Note - you might have to have the control's post disabled. Not sure.

Upvotes: 0

Related Questions