日期:2014-05-18  浏览次数:20394 次

asp.net后台调用js
<asp:TemplateField HeaderText="地址">
  <ItemTemplate>
  <asp:Label ID="onetwo" runat="server"></asp:Label>
  </ItemTemplate>
  <HeaderStyle Height="25px" />
  <ItemStyle BorderStyle="Ridge" HorizontalAlign="Center" />
  </asp:TemplateField>
------------------------------------------------------.aspx页面 这是gridview里的一个模板列
for (int i = 0; i < this.stopGV.Rows.Count; i++)
  {
  Label lbaddress = (Label)this.stopGV.Rows[i].Cells[7].FindControl("onetwo");
  lbaddress.Attributes.Add("onload", "showAddress(onetwo,121.557284,29.825411);");
  }
-------------------------------------------------------.aspx.cs文件

js是在另一个页面里

我的需求就是 通过后台 调用 另一个页面的js 然后 可以在 id为onetwo的label上显示这个js的结果,但是实际情况是这样写没有报错 但是地址这一栏什么信息也没有是 空的(注,js测试过,没有错误),请大虾帮忙

------解决方案--------------------
比如
String x = "";
for (int i = 0; i < this.stopGV.Rows.Count; i++)
{
Label lbaddress = (Label)this.stopGV.Rows[i].Cells[7].FindControl("onetwo");
x+= "showAddress('onetwo',121.557284,29.825411);";
}


Page.ClientScript.RegisterStartupScript(Page.GetType(),"x",x,true);
------解决方案--------------------
onetwo 看下是不是ID错了
控件生成HTML id应该会变,你先运行页面,看生成的HTML ID 是什么 然后在把这个ID

lbaddress.Attributes.Add("onload", "showAddress(前天页面HTML对应的id,121.557284,29.825411);");