[英]How to call javascript method when user clicks on button(not on page_loadcomplete)?
Tried Google but couldn't find my answer, So posting it here. 尝试过Google,但找不到我的答案,因此请在此处发布。
SS is attached in last. 最后附加SS。 When the user clicks on download button, some actions performed on backend ie file transfer and when the process is completed, it changes the label text of "Total"
当用户单击下载按钮时,将在后端执行一些操作,即文件传输,并且在该过程完成后,它将更改“总计”的标签文本
I want to change the label text of the div. 我想更改div的标签文本。
I have tried "RegisterStartupScript" also in place of "RegisterClientScriptBlock" 我也尝试过使用“ RegisterStartupScript”代替“ RegisterClientScriptBlock”
But didn't work 但是没用
Tried by setting innerHtml from c# also didn't work 通过从C#设置innerHtml进行的尝试也不起作用
C# C#
protected void btnrepeat()
{
//my code for load balancing
Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript21211", "UpdateServerMax('" + server1max + "')", true);
//LabelServer1Max.InnerHtml = server1max.ToString();
}
JavaScript JavaScript的
function UpdateServerMax(server1Max) {
alert("njk");
LabelServer1Max.innerHTML = server1Max;
}
HTML HTML
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count" style="margin-bottom: -1%">
<br />
<span class="count_top"><i class="fa fa-user"></i>Total </span>
<div class="count" id="LabelServer1Max" runat="server">
4,567</div>
</div>
Also tried removing runat="server" from div. 还尝试从div中删除runat =“ server”。
Here is the SS what i want to change. 这是我要更改的SS。 https://ibb.co/kZ2Zvk
https://ibb.co/kZ2Zvk
The 4th label says "Total". 第四个标签显示“总计”。
You can update the value from C# after the Page_Load event.It can be somethig like this 您可以在Page_Load事件之后从C#更新值。
protected void Page_Load(object sender, EventArgs e)
{
LabelServer1Max.Text= server1Max;
}
or after the Page_LoadComplete Event 或在Page_LoadComplete事件之后
void Page_LoadComplete(object sender, EventArgs e)
{
LabelServer1Max.Text= server1Max;
}
Add it to your .cs file. 将其添加到您的.cs文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.