ASP.NET图片src问题 [英] ASP.NET image src question
本文介绍了ASP.NET图片src问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过以下的jQuery code设置图像控件的值:
I set the value of a image control via the following jquery code:
$('.image').click(function () {
var imgPath = $(this).attr('src');
var imgName = imgPath.substring(0, imgPath.length - 4);
var imgAlt = $(this).attr('alt');
$('#<%= detailedImage.ClientID %>').
attr('src', imgName + '-large.jpg').
attr('alt', imgAlt);
图像完美显示在浏览器中。不过,我不能访问它的的src
属性:
string imgName = detailedImage.Src;
imgName
始终是一个空字符串。有什么建议?
imgName
is always an empty string. Any suggestions?
推荐答案
更改的src
的 IMG
,即使 IMG
被放置在一个&LT;形式&GT;
不提交 SRC
到服务器。您需要设置新的的src
的东西将在形式提交,即一个隐藏字段。试试这个:
Changing the src
of an img
, even though the img
is placed within a <form>
doesn't submit the src
to the server. You need to set the new src
in something that will be submitted in the form, i.e. a hidden field. Try this:
$('.image').click(function () {
var imgPath = $(this).attr('src');
var imgName = imgPath.substring(0, imgPath.length - 4);
var imgAlt = $(this).attr('alt');
var src = imgName + '-large.jpg';
$('#<%= detailedImage.ClientID %>').
attr('src', src).
attr('alt', imgAlt);
$('#<%= hiddenInput.ClientID %>').val(src);
});
如果你现在在你的标记是这样的:
If you now have something like this in your markup:
<input type="hidden" id="ImageSource" runat="server" />
您应该能够检索 ImageSource.Value
服务器端。
You should be able to retrieve ImageSource.Value
server-side.
这篇关于ASP.NET图片src问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文