[英]Ajax update panel not letting javascript to work form server side?
Whenever i try to call a javascript function from code behind file, it is not functional. 每当我尝试从文件后面的代码调用javascript函数时,它就无法正常工作。
The root cause is Ajax update panel. 根本原因是Ajax更新面板。
I have tried all the common solution like using ScriptManager.RegisterStartupScript
and other but still not functional. 我已经尝试了所有常见的解决方案,例如使用
ScriptManager.RegisterStartupScript
和其他解决方案,但仍然无法正常工作。
Below is my code: 下面是我的代码:
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gvTemp = (GridView)sender;
gvUniqueID = gvTemp.UniqueID;
gvTemp.EditIndex = e.NewEditIndex;
GridViewRow gvParentRow = gvTemp.Parent.Parent as GridViewRow;
GridView parent = (GridView)gvParentRow.NamingContainer;
int taskid = Convert.ToInt32(parent.DataKeys[gvParentRow.RowIndex].Value.ToString());
var lstTaskSheets = (List<Entities.TaskSheetManagement>)Session["CurrentUserTaskSheets"];
List<Entities.WorkDone> lstWorkdone = lstTaskSheets.Where(x=>x.TaskSheetId == taskid).SelectMany(c => c.WorkDones).ToList();
gvTemp.DataSource = lstWorkdone;
gvTemp.DataBind();
UpdatePanelGridView.Update();
string id = "div"+ taskid.ToString();
ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(), "Expand", "<script type='text/javascript'>expandcollapse('div" + taskid.ToString() + "','one');</script>",false);
// ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "message", "expandcollapse(" + id + ",alt)", false); //Ihave also tried this
}
Javascript code is: JavaScript代码是:
function expandcollapse(obj, row) {
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none") {
div.style.display = "block";
if (row == 'alt') {
img.src = "../../img/minus.gif";
}
else {
img.src = "../../img/minus.gif";
}
img.alt = "Close to view other Customers";
}
else {
div.style.display = "none";
if (row == 'alt') {
img.src = "../../img/plus.gif";
}
else {
img.src = "../../img/plus.gif";
}
img.alt = "Expand to show Orders";
}
}
and update panel is used like 和更新面板使用像
<asp:UpdatePanel ID="UpdatePanelGridView" runat="server" UpdateMode="Conditional" >
Anyone help please!!! 任何人都请帮助!!!
You don't need to use the <script>
tags like below : 您不需要使用
<script>
标记,如下所示:
ScriptManager.RegisterStartupScript(this.Page,this.Page.GetType(), "Expand", "<script type='text/javascript'>expandcollapse('div" + taskid.ToString() + "','one');</script>",false);
Replace the arguement: 替换论点:
"<script type='text/javascript'>expandcollapse('div" + taskid.ToString() + "','one');</script>"
With below: 以下:
"expandcollapse('div" + taskid.ToString() + "','one');"
The ScriptManager is smart enough to append the script tags. ScriptManager非常聪明,可以附加脚本标签。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.