如何从asp.net服务器控件使用jQuery传递价值? [英] how to pass value from asp.net server control using jQuery?
本文介绍了如何从asp.net服务器控件使用jQuery传递价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我更新了code。与code后面。我在做一些动态与标签contrtol。
我有以下的jQuery code的工作,因为它是(合格的检验值),但我想要做的是通过标签控制(lblNames)的价值。我使用的标签控制收集上传的文件名。有什么办法?
jQuery的:
$(文件)。就绪(函数(){
$(#btnUpload)。点击(函数(){
$(#注意事项,top.document).VAL('测试');
});
});
ASPX code:
< ASP:标签ID =lblNames=服务器可见=真>< / ASP:标签>
code背后:
保护小组btnUpload_Click(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手btnUpload.Click
昏暗fileExt作为字符串
fileExt = System.IO.Path.GetExtension(FileUpload1.FileName) 如果(fileExt<>中的.exe),然后
昏暗的文件名作为新的列表(串) 尝试
昏暗的HFC作为HttpFileCollection = Request.Files
lblFiles.Text =的String.Empty
lblNames.Text =的String.Empty 对于我作为整数= 0〜hfc.Count - 1
DIM HPF作为HttpPostedFile = HFC(I)
如果hpf.ContentLength> 0,则
fileNames.Add(hpf.FileName)
hpf.SaveAs(使用Server.Mappath(/目录)及\\&放大器; System.IO.Path.GetFileName(hpf.FileName))
lblFiles.Text + =< B>文件:LT; / B>中&安培; hpf.FileName&安培; 与& 上传成功<!BR />中
lblNames.Text + = hpf.FileName&安培; ,
其他
lblWarning.Text =请选择要上传的文件。
万一
接下来,我
抓住EX为例外 结束Try
解决方案
您可以轻松地插入该ID到脚本,将其拉出这种方式:
$(文件)。就绪(函数(){
$(#btnUpload)。点击(函数(){
$(#注意事项,top.document).VAL($(#<%= lblNames.ClientID%GT;)文本());
});
});
I UPDATED the code with code behind. I'm doing something dynamic with the label contrtol.
I have the following jQuery code working as it is (passing the value of 'test") but what I want to do is to pass the value of the label control (lblNames). I'm using the label control to collect the uploaded file names. Is there a way?
jQuery:
$(document).ready(function () {
$("#btnUpload").click(function () {
$("#Notes", top.document).val('test');
});
});
ASPX code:
<asp:Label ID="lblNames" runat="server" visible="true" ></asp:Label>
Code Behind:
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
解决方案
You can easily insert the ID into your script and pull it out that way:
$(document).ready(function () {
$("#btnUpload").click(function () {
$("#Notes", top.document).val( $("#<%= lblNames.ClientID %>").text() );
});
});
这篇关于如何从asp.net服务器控件使用jQuery传递价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文