0

我有一个返回字符串(部分描述)的 httphandler。

我想在title图像的属性中使用返回值,该值将在页面加载时更新。

我在 page_load 事件中有以下代码...

imgThumbnail.Attributes.Add("title", "~/Views/Admin/ImageRepository/ShowDescription.ashx?partno=123456&view=thumb");

我不确定如何让title文本成为返回值,而不仅仅是"~/Views/Admin/ImageRepository/ShowDescription.ashx?partno=123456&view=thumb".

我怎样才能做到这一点?这是第一次使用 http 处理程序。我已经测试了处理程序,它确实返回了我期望的字符串。

4

1 回答 1

0

我认为您可能需要重新考虑如何处理此问题,您的代码可能如下所示:

string imgTitle = "Image Title"; // you need to set the value of imgTitle here.
imgThumbnail.Attributes.Add("title", imgTitle);

这可能会给出如下输出:

<img title="Image Title" />

您可能不需要处理程序,本质上,您可以将代码从处理程序移动到您的页面。

string imgTitle = GetImageTitle(partno); // you need to set the value of imgTitle here.
imgThumbnail.Attributes.Add("title", imgTitle);

public string GetImageTitle(string partno)
{
   // put code to return image title here;
}

PS你确定你不想要alt属性,<img>没有title属性。

于 2013-04-29T11:30:05.180 回答