【问题标题】:httphandler return into string variablehttphandler 返回字符串变量
【发布时间】:2013-04-29 10:54:06
【问题描述】:

我有一个返回字符串(部分描述)的 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 处理程序。我已经测试了处理程序,它确实返回了我期望的字符串。

【问题讨论】:

  • 处理程序似乎不是解决此问题的正确解决方案 - 作为用户当前请求的一部分,您将不得不在处理程序注册的任何地方向处理程序发起完整的请求。跨度>

标签: c# asp.net string httphandler


【解决方案1】:

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

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 属性,&lt;img&gt; 没有title 属性。

【讨论】:

  • 谢谢,我确实需要 title 属性,因为我正在使用 jqueryui 工具提示。我将重新考虑如何获取描述。描述与产品图像一起存储在数据库中。我正在使用类似的处理程序来返回产品的图像,并认为我可以对描述做同样的事情。
猜你喜欢
  • 2015-11-01
  • 2013-09-18
  • 1970-01-01
  • 2018-04-20
  • 1970-01-01
  • 2023-03-15
  • 2017-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多