gpt4 book ai didi

asp.net - 如何使用 jQuery 从 ASP.NET 服务器控件传递值?

转载 作者:行者123 更新时间:2023-12-01 03:55:02 25 4
gpt4 key购买 nike

我用后面的代码更新了代码。我正在使用标签控件做一些动态的事情。

我有以下 jQuery 代码按原样工作(传递“test”的值),但我想做的是传递标签控件(lblNames)的值。我正在使用标签控件来收集上传的文件名,有办法吗?

jQuery:

$(document).ready(function () {
$("#btnUpload").click(function () {
$("#Notes", top.document).val('test');
});
});

ASPX 代码:

<asp:Label ID="lblNames" runat="server" visible="true" ></asp:Label>

背后代码:

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs)    Handles btnUpload.Click
Dim fileExt As String
fileExt = System.IO.Path.GetExtension(FileUpload1.FileName)

If (fileExt <> ".exe") Then
Dim fileNames As New List(Of String)

Try
Dim hfc As HttpFileCollection = Request.Files
lblFiles.Text = String.Empty
lblNames.Text = String.Empty

For i As Integer = 0 To hfc.Count - 1
Dim hpf As HttpPostedFile = hfc(i)
If hpf.ContentLength > 0 Then
fileNames.Add(hpf.FileName)
hpf.SaveAs(Server.MapPath("/directory") & "\" & System.IO.Path.GetFileName(hpf.FileName))
lblFiles.Text += "<b>File: </b>" & hpf.FileName & " " & " Uploaded Successfully! <br />"
lblNames.Text += hpf.FileName & ", "
Else
lblWarning.Text = "Please choose a file to upload."
End If
Next i
Catch ex As Exception

End Try

最佳答案

您可以轻松地将 ID 插入脚本中并以这种方式将其取出:

$(document).ready(function () {
$("#btnUpload").click(function () {
$("#Notes", top.document).val( $("#<%= lblNames.ClientID %>").text() );
});
});

关于asp.net - 如何使用 jQuery 从 ASP.NET 服务器控件传递值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3620975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com