Javascript 中继器内部的链接按钮详细信息部分
我在中继器控件的deatail部分中有链接按钮。在编辑时,asp.net文本框将启用“更改回色”。保存时,值将保存到数据库中。为了避免回发,我被迫将服务器端代码更改为javascript函数。我如何编写函数,以便在单击linkbutton时在java脚本中执行相同的操作。对于Update link button->,是否可以在javascript中执行相同的操作功能 提前谢谢Javascript 中继器内部的链接按钮详细信息部分,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我在中继器控件的deatail部分中有链接按钮。在编辑时,asp.net文本框将启用“更改回色”。保存时,值将保存到数据库中。为了避免回发,我被迫将服务器端代码更改为javascript函数。我如何编写函数,以便在单击linkbutton时在java脚本中执行相同的操作。对于Update link button->,是否可以在javascript中执行相同的操作功能 提前谢谢 <asp:LinkButton ID="lnkEdit" runat="server" Comm
<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
编辑
更新
如果e.CommandName=“编辑”,则
DirectCast(e.Item.FindControl(“TextBox2”),TextBox).Enabled=True
DirectCast(例如Item.FindControl(“Textbox2”),TextBox.BorderStyle=BorderStyle.NotSet
DirectCast(例如Item.FindControl(“Textbox2”),TextBox.BackColor=Drawing.Color.White
如果结束
如果e.CommandName=“更新”,则
Dim bookName为String=DirectCast(例如Item.FindControl(“Textbox2”),TextBox.Text
Dim author As String=DirectCast(例如Item.FindControl(“TextBox3”),TextBox.Text
Dim pub As String=DirectCast(例如Item.FindControl(“TextBox4”),TextBox.Text
Dim price As String=DirectCast(例如Item.FindControl(“TextBox5”),TextBox.Text
Dim adp作为新的SqlDataAdapter(“更新abc集合许可=@License,StartDate=@StartDate,Renewal=@Renewal,VendorPONo=@VendorPONo,其中LicenseID=@LicenseID”,con)
adp.SelectCommand.Parameters.AddWithValue(“@LicenseName”,bookName)
adp.SelectCommand.Parameters.AddWithValue(“@StartDate”,作者)
adp.SelectCommand.Parameters.AddWithValue(“@Renewal”,pub)
adp.SelectCommand.Parameters.AddWithValue(“@VendorPONo”,price)
adp.SelectCommand.Parameters.AddWithValue(“@LicenseID”,e.CommandArgument)
将ds作为新数据集()进行调整
自动填充(ds)
BindRepeater()
如果结束
编辑
当我尝试按如下方式启用文本框时,“TextBox4”未声明。由于显示其保护级别错误,可能无法访问
<script type="text/javascript">
function MyJSFunction() {
var textBox = document.getElementById("<%=TextBox4.ClientID %>");
textBox.enabled = true;
textBox.focus();
}
</script>
函数MyJSFunction(){
var textBox=document.getElementById(“”);
textBox.enabled=true;
textBox.focus();
}
如果我理解正确,您要找的是OnClient Click?您可以从客户端的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>
我用“return false”编辑了aswer。多亏了adcd shsu,我得到了通过Javascript函数避免回发的答案
下面的链接帮助我解决了这个问题。感谢所有的支持
对不起……在编写MyJSFunction()Update时,我可以在java脚本函数ie中执行相同的(更新)操作吗?我正在寻找使中继器内的文本框处于启用状态的“javascript函数”。(单击链接按钮一次)