中继器详细信息部分中的链接按钮

Link Button inside Repeater detail section

本文关键字:链接 按钮 信息部 中继器      更新时间:2023-09-26

我在中继器控件的deatail部分内有链接按钮。在编辑时,asp.net 文本框将启用并更改回颜色。在保存时,值将保存到数据库中。为了避免回发,我被迫将服务器端代码更改为javascript函数。我如何编写函数以在单击链接按钮时在 java 脚本中执行相同的操作。对于更新链接按钮 ->是否可以在 Javascript 函数中执行相同的操作。

提前谢谢。

         <asp:LinkButton ID="lnkEdit" runat="server" CommandName="edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "LicenseID") %>' CausesValidation="False" onClientClick="JSFunction();return false">Edit</asp:LinkButton>
         <asp:LinkButton Visible="true" ID="LinkButton5" runat="server" CommandName="update"    CommandArgument='<%# DataBinder.Eval    (Container.DataItem, "LicenseID") %>'   CausesValidation="False" onClientClick="MyJSFunction();return  false" >Update</asp:LinkButton>
 If e.CommandName = "edit" Then
      DirectCast(e.Item.FindControl("TextBox2"), TextBox).Enabled = True
      DirectCast(e.Item.FindControl("Textbox2"), TextBox).BorderStyle = BorderStyle.NotSet
      DirectCast(e.Item.FindControl("Textbox2"), TextBox).BackColor = Drawing.Color.White
  end if 
 If e.CommandName = "update" Then
            Dim bookName As String = DirectCast(e.Item.FindControl("Textbox2"), TextBox).Text
            Dim author As String = DirectCast(e.Item.FindControl("TextBox3"), TextBox).Text
            Dim pub As String = DirectCast(e.Item.FindControl("TextBox4"), TextBox).Text
            Dim price As String = DirectCast(e.Item.FindControl("TextBox5"), TextBox).Text
            Dim adp As New SqlDataAdapter("Update abc set License= @License, StartDate=@StartDate,Renewal=@Renewal,VendorPONo=@VendorPONo where LicenseID = @LicenseID", con)
            adp.SelectCommand.Parameters.AddWithValue("@LicenseName", bookName)
            adp.SelectCommand.Parameters.AddWithValue("@StartDate", author)
            adp.SelectCommand.Parameters.AddWithValue("@Renewal", pub)
            adp.SelectCommand.Parameters.AddWithValue("@VendorPONo", price)
            adp.SelectCommand.Parameters.AddWithValue("@LicenseID", e.CommandArgument)
            Dim ds As New DataSet()
            adp.Fill(ds)
            BindRepeater()
        End If

编辑

当我尝试启用文本框时,如下所示,未声明"TextBox4"。由于显示其保护级别错误,它可能无法访问

       <script type="text/javascript">
      function MyJSFunction() {
          var textBox = document.getElementById("<%=TextBox4.ClientID %>");
          textBox.enabled = true;
            textBox.focus();
      }
</script>

如果我理解正确,您正在寻找的是OnClientClick?您可以从客户端的 Linkbutton 控件的 OnClientClick 事件调用 javascript 函数。

<asp:LinkButton Visible="false" ID="lnkUpdate" runat="server" 
CommandName="update"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "LicenseID") %>' 
CausesValidation="False" OnClientScript='MyJSFunction();return false'>Update</asp:LinkButton>

看看这个 : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.onclientclick.aspx

我用"返回假"编辑了 aswer。感谢 adcd shsu

我得到了避免通过 Javascript 函数回发的答案。

下面的链接帮助我解决了这个问题。感谢大家的支持。

http://forums.asp.net/p/1949196/5559671.aspx?p=True&t=635199146113886958&pagenum=1