我在中繼器控件的deatail部分內部有鏈接按鈕。在編輯中,asp.net文本框將變爲啓用,並更改回色彩。保存值將保存到數據庫。避免回發我強制要將服務器端代碼更改爲javascript函數。如何在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, [email protected],[email protected],[email protected] 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>
對不起...我可以做同樣的(更新)在IE瀏覽器的Java腳本函數爲你寫MyJSFunction() –
的 Update asp :LinkButton> –
我在尋找的是使轉發器啓用文本框的「javascript函數」。 (點擊鏈接按鈕) –