在javascript中获取元素

时间:2013-02-21 21:59:10

标签: javascript asp.net html .net repeater

我有一个Repeater我正在为它绑定一些数据。现在我的问题是如何在javascript的转发器中引用我标签中的数据。我的代码如下;

代码隐藏

protected void Page_Load(object sender, EventArgs e)
 {

 // bool boolfound = false;
 string connstring = String.Format("Server=localhost; Port=5432; User Id=postgres; Password=database; Database=valletta;");

 using (NpgsqlConnection conn = new NpgsqlConnection(connstring))
 {
  try
   {
    conn.Open();

    NpgsqlCommand cmd = new NpgsqlCommand("select get_points('temp_intersect', 'point','id',17339)", conn);
    NpgsqlDataReader dr = cmd.ExecuteReader();

    currentpoint.DataSource = dr;
    currentpoint.DataBind();

   }
   catch (Exception)
   {
    ClientScript.RegisterStartupScript(this.GetType(), "", "$(document).ready(function(){alert('problem with connection')});", true);
   }
 }

}

ASP

<asp:Repeater ID="currentpoint" runat="server">
   <ItemTemplate>
     <div>
       <asp:Label ID="hiddenlabel" runat="server" Text='<%# Eval("get_points")%>' Visible="false">
       </asp:Label>
      </div>
    </ItemTemplate>
 </asp:Repeater>

2 个答案:

答案 0 :(得分:3)

您可以将ClientIDMode更改为Predictable或static,适用于javascript。

阅读this post

答案 1 :(得分:1)

试试这个:

document.getElementById('<%=currentpoint.FindControl("hiddenlabel").ClientID%>')