简体   繁体   English

单击按钮更改UpdateProgress文本

[英]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. 例如,我需要在单击按钮时使用UpdateProgess更改文本。

This is my ascx : 这是我的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 这是我在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! 谢谢!

Your UpdateProgress is outside the UpdatePanel but your button is inside the update panel. 您的UpdateProgress在UpdatePanel外部,但是您的按钮在更新面板内部。

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. 当您使用更新面板,所有的更新面板内部的控件将在阿贾克斯工作,他们不会做真正的职位,但Ajax请求。 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. 继续,如果您希望它起作用,请在更新面板中添加更新进度控件,它将起作用。

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. 如果要更改标签文本而不进行刷新,则需要使用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. 不确定。

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";});                 
    }    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM