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

时间:2013-11-04 08:38:16

标签: javascript asp.net vb.net

我在转发器控件的deatail部分内有链接按钮。在编辑时,asp.net文本框将变为启用后更改颜色.On保存值将保存到数据库。为了避免回发我被迫将服务器端代码更改为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>

2 个答案:

答案 0 :(得分:1)

如果我理解正确,你要找的是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

我用'return false'编辑了aswer。感谢adcd shsu

答案 1 :(得分:0)

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

以下链接帮助我解决了这个问题。感谢所有支持。

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