2014年7月13日 星期日

[RESOLVED] how to get lable's text by .ashx handler in repeater control


I have a lable within a

in repeater.  I have a httphandler named "NameShow.ashx" to return the "name" as "text/plain" by passing an "id" to handler.


I want to retrieve the "name" (similer to retrieving "image" from handler).


Here is my code. I am getting the text of this lable as ->> NameShow.ashx?id=123


Here is my code of field.Please help in finding where I am doing mistack.




Remove extra double quote,




Will you please write the code which wuote you are talking about?


By the way I have did all try by changing the quotes. Nothing have been changed.




Hi chamansaini,


I'm not sure if I understand you exactly. Is the http handler "NameShow.ashx?id=xxx" within the same web application as your web page (in which your repeater is added)? If it is, why not directly writing a helper method to retrieve the name (maybe from database)
by a given id info? The following expression will not work:


<%#""NameShow.ashx?id="+Eval("id") %>


because the ASP.NET runtime will only evaluate the C# expression and output the plain text info (the url in this case here) in the respones html. If you want to let it access the HTTP handler's url and retrieve the response "name" field back, you need write
your own funciton (in page class) to do it. For exampmle, you can write a helper function in page's code behind which use HttpWebRequest class to access the httphandler (with id parameterss) and parse the name field from the response content:


#HttpWebRequest Class

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx


#Retrieving HTTP content in .NET

http://www.west-wind.com/presentations/dotnetWebRequest/dotnetWebRequest.htm


Then, your <%# %> expression can invoke the helper method. But having such a helper method invoked repeatedly for each repeater item will significantly impact the page's response performance (it spends time for each WebRequest operation to finish). Therefore,
I'd suggest you reconsider the current design to see if we can implement the same feature with different approaches.


沒有留言:

張貼留言