Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have an image and I want to get image url with method .I found this questions on the web.But answer not quite.
Source as follows:
<img id="largeImage" src='<%#ShowLast() %>' alt="" />
cs file as follows:
public string ShowLast()
{
using (DBMLDataContext dc=new DBMLDataContext())
{
var query = (from d in dc.News
select d).Last();
return query.Photo.ToString();
}
}
Whats happening? If you are using this inside a databound control then <%# is right. If not you will want to use <%= or better yet one of the variations that encode the output.
Based on your comments it sounds like you should just use an <asp:Image> control and then set its ImageUrl property in the codebehind.
Markup:
<asp:Image runat="server" id="largeImage" GenerateEmptyAlternateText="True" />
Code Behind:
// in page load
largeImage.ImageUrl = ShowLast();
The only gotcha I can think of with this approach is if you are using the id "largeImage" in your css or somesuch. Converting it to an asp.net control means it will take control of the ID so you will need to target it through your css with a CssClass property or if you are using a modern version of .net you also have some other options to set the ID to a static id - I'll update again if this is an issue.
You can call the method like this
<img id="largeImage" src='<%= ShowLast() %>' alt="" />
if method is returning URL in string
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have attached a folder to my project solution explorer (ASP.NET) that includes all the images I may retrieve their names from the database for output. Images names stored in the database as paths:
<img src="~/#item.Logo" width="120" height="120" />
the problem is that i am not getting the images displayed in the browser! when I output the value of #item.Logo and copy/paste it in the HTML tag the images were shown!
can anyone tell me what is the wrong thing i am doing here ?
Try using Url.Content() helper:
<img src="#Url.Content("~/item.Logo")" width="120" height="120" />
~ sign means root directory of solution.
Try this :
#model IEnumerable<YourModelClass>
#foreach (var item in Model){
<img src='"PathOfYourFolder" + #Url.Content("DatabaseImageFieldName")' />}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Good morning,
I have the following asp Image and would like to add the on mouse over event, as follow:
<asp:Image ID="MapImage" runat="server" Height="601px" Width="469px" OnMouseOver="OnMouseOverMap"/>
I have also added the following method on the C# code:
protected void OnMouseOverMap(object sender, EventArgs e)
{
int i = 9;
}
I also have created the same method without the parameters but I cannot manage to call that C# function.
Can somebody help me with this issue?, How can I do to call the C# function from the ASP code.
Cheers!
There is no OnMouseOver server-side event on asp:Image object.
What you can do you can write js function called on client-side onmouseover event and inside that function trigger click on hidden button or you can change Image to ImageButton and trigger click on that image.
<asp:Image ID="MapImage" runat="server" Height="601px" Width="469px" onmouseover="javascript:foo()"/>
<asp:Button ID="Button1" runat="server" style="display:none" OnClick="OnMouseOverMap" />
And in js function:
function foo()
{
document.getElementById('<%= Button1.ClientID %>').click();
}
I am pretty sure that you are supposed to insert javascript code there and not a "code behind event handler reference". See ASP NET image onmouseover not working for example.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can someone give an idea how I can see details of a selected product (suppose) regarding The productID in another page with HyperLink?? I have Tried To pass The ID with QueryString with Linq. But not done.
Mark up
<asp:HyperLink ID ="hyperLink" runat="server" />
C#
Set the url:
hyperLink.NavigateUrl = "somePage.aspx?id=123";
Read the url query string in somePage.aspx
var id = Request.QueryString["id"];
You have multiple problems in your code (as given in your comment section).
Here is what you have
<asp:HyperLink ID = "View" server = "runat" NavigateUrl = '<%# ("~/pageredirect.aspx") + eval("CatergoryID") %>'>View</asp:HyperLink>
Issues:
you have server = "runat" and it should be runat="server"
you are concatenating CatergoryID with the redirect page and not really passing as querystring which will really append the value like pageredirect.aspx + categoryid
you are binding as CatergoryID and retrieving by query string name CategoryID which is not same (notice the typo)
Change your asp:HyperLink definition in the itemtemplate of the gridview in Approve.aspx as below
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hlView" runat="server" NavigateUrl='<%# Eval("CategoryID", "~/pageredirect.aspx?CategoryID={0}") %>' Text="View" />
</ItemTemplate>
</asp:TemplateField>
and then in your pageredirect.aspx.cs access the querystring value as
if (!String.IsNullOrEmpty(Request.QueryString["CategoryID"]))
{
int m = Int32.Parse(Request.QueryString["CategoryID"]);
....
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am using hidden type form value in HTML. how we connect this with javascript and jquery.
I tried this:
HTML :
<label>Company Name:</label><br />
<input type="text" name="21602-0" id="21602-0" size="30" value="<%= FormValues["21602-0"] % />
JS:
vars[1] != null ? $('#21620-' + index.toString()).val(vars[1]) : $('#21620-' + index.toString()).val('');
Hidden fields are those fields as their name suggest which are not visible on UI (but available in source html), you can maintain state of some element using these field.
Now to access these field by name using jQuery try:
var text = $('[name="ElementNameHere"]').val();
and to set field value:
$('[name="ElementNameHere"]').val('new Text');
and using JavaScript:
var text = document.getElementsByName('ElementNameHere').value;
//or set new text
document.getElementsByName('ElementNameHere').value= 'new text';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have some customers in a gridview. When I click on the customers I can get their names in a textbox. There is also a corresponding pdf document which should also be available if the user desires.
My problem is that I need to know who to open a pdf document using C# and asp.net. I have to use a variable name as the name of pdf document, for example when the click on a button "open variable CustomerName.pdf".
I need to open a pdf file in a new window for viewing
thanks
this works
asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/customerUnit/Customer.pdf" Target="_blank">HyperLink
But I want to pass the pdf file as a variable "Customer.pdf" should be "VaribleCustmer.pdf"
I agree with #Ahmed from the comments, you shouldn't over-think this:
Simply link to the CustomerName.pdf if your using a hyperlink.
Simply redirect to the CustomerName.pdf if your using a button
But I want to pass the pdf file as a variable "Customer.pdf" should be "VaribleCustmer.pdf"
Asp Markup:
<asp:HyperLink ID="HyperLink1"
runat="server" Target="_blank">
Code behind:
var pdfFile = "Customer.pdf"; //or VaribleCustmer.pdf
HyperLink1.NavigateUrl= String.Format("~/customerUnit/{0}", pdfFile);