Open image on next aspx page - asp.net

I show image thumbnails on page, Now I want when i click on image thumbnail the big images related to that thumbnail open in IamgeDispData.aspx page where i created a data entry form in that page to enter data related to that picture. How can I do this? With help of query string or else??

Query String is a good option.
What you can do put your image inside a asp:hyperlink
Set the URL of asp:hyper link with querysting
And in your detail page get it from url
Note that you can only pass the filepath in the url
And you will have to show it from the physical location

With help of query string ??
Yes, you can use it. Just surround your image with <a> anchor tag or use asp:hyperlink server side tag.
It can be something like
Content/Thumbnails/page.aspx?imageName="your image name"
e.g.
<a href="http://www.espn.com" target="_blank">
<img src="ahman.gif" />
</a>
Ref:
html - image links
Hyperlink image
How to control the image size of a Hyperlink?
example code snippet:
<asp:HyperLink runat="server" ID="hlThumbnail" NavigateUrl='<%# Eval("Url") %>'
Target="_blank" Style="height: 66px;">
<asp:Image runat="server" ID="imgThumbnail" Height="66px"
ImageUrl='<%# Eval("Thumbnail") %>' />
</asp:HyperLink>

In case you have no issue in showing Id to user , it will be the best solution. In case you have some issue in showing Id , you can encrypt it and then use it as Id. You can also validate then user again in the ImageDispData.aspx if he has the permission to enter the data or not for the image.
I am giving way to use using querystring and javascript.
You can use window.open function of JavaScript to open in new window or tab. When you are generating the thumbnail image , create them with url like : yourBigimage.aspx?photoId=10 , open this url using jquery onclick event of image and use window.open

Related

design a button with a custom image? is it possible?

Is it possible to put a button on my user control .ascx (the web part in this case), and have a customized image with that? What I am trying to do is have a "print" button to print the page.
However, I don't want to use the default asp button, I want to have a the special "print" icon associated with it. So, can I do this and still use <asp:button>?
Or is it just better to make that "print" icon a link, and do OnClick on the link event?
You can use link button as suggested.
But in my opinion you should not use any server-side control if you don't have to use it on server side.
What you can do create an image tag <img src.... and use onclick event on this image.
When you create a server side controls it is added to your view state key value pair of information. Which is an overhead.
or you can use like this
<a href="javascript:window.print()">
<img src="print.gif">
</a>
or even
<img src="print.gif" name="pic" onclick="javascript:window.print()"/>
You could try the ImageButton class, then you can have a printer icon for example.
Try this:
<asp:ImageButton ID="submitButton" runat="server" OnClick="submitButton_Click" ImageUrl="~/images/printer.jpg" />

Anchor tag not poining towards the exact url?

I am using repeater control in my web page.I am using an anchor tag and an image within the repeater.The idea is when the page loads the image and corresponding URL should be loaded from the database.
The problem is when i point the cursor on the image,instead of exact URL the URL is combined with the project name.
For example the URL i should get is www.facebook.com,but what i am getting is
localhost:64396/CMS/www.facebook.com
The repeater control i have used is furnished below
<asp:Repeater ID="rpt_img_footer" runat="server">
<ItemTemplate>
<a href="<%#Eval("IMAGE_URL") %>"><img alt="<%#Eval("IMAGE_NAME") %>"
src="<%#Eval("IMAGE_PATH") %>" width="32px" height="33px" /></a>
</ItemTemplate>
</asp:Repeater>
You should include the protocol in the src attribute as well, try it with http:// in front : http://www.facebook.com instead of just www.facebook.com.
Otherwise it'll be src definition relative to the path of the page itself.

Colorbox and ASP.NET in a bound Datalist

My images are stored in a SQL database. I bind to the table and use the generated image control and a ashx handler. No problem. I now have the thumbnail image surrounded by a anchor tag. The problem come in finding the large image thats in a hidden div and display ONLY that.. I don't want a gallery just that one image. If you are reading this you know that datalists when generating their controls assigns mangled ID's to their components. How can I address that image from my thumbnail image?
<asp:DataList ID="datalist" runat="server" RepeatColumns="3" RepeatDirection="Horizontal">
<ItemTemplate>
<a class="colorme" href="#">Actual thumbnail image</a>
<div style="display:none">
<div id="colorme" runat="server">Actual image to display
</div>
</div>
</ItemTemplate>
</asp:DataList>
ASP.NET 4.0 no master page.
Assign ID and run at server for your Image and use
<%= yourimage.ClientID %> this will return that particular image wherever you'll use it..not the mangled IDs generated by Datalist control.
The simplest solution would be to use jQuery, and find the element using the next-sibling selector.
$(".colorme").click(function(){
$(this).find("~ div").show();
});
This would work no matter how many images you have on the page.

How to show Image with http url in asp.net

In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
Now I want to display it on my datalist. But it is not showing any image. It is might be the case because it is expecting the Image URL to be ~/Folder/abc.jpg
Then how to show the image on the asp.net page when I have image URL, which control I need to use and how?
Do you see little red X instead of an image?
If so, right click it --> Properties (IE) to see the URL it's referring to.
Might give us hint on what's going on. :)
If you are getting the image from the database in for the form xzy.com/1009/image1.jpg but want to add the http:// then your code should be
<asp:Image ID="imgmain" runat="server" ImageUrl='<%#String.Format("http://{0}", Eval("Image"))%>' Width="80" Height="80" />

link button property to open in new tab?

In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or Open in new window.
How do I show those menu items?
Code example:
<asp:LinkButton id="lbnkVidTtile1" runat="Server" CssClass="bodytext" Text='<%#Eval("newvideotitle") %>' />
From the docs:
Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.
As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.
Depending on what you are trying to do you could either:
Use a HyperLink control, and set the Target property
Provide a method to the OnClientClick property that opens a new window to the correct place.
In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
Here is your Tag.
<asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>
Here is your code on the code behind.
LinkButton1.Attributes.Add("href","../Test.aspx")
LinkButton1.Attributes.Add("target","_blank")
Hope this will be helpful for someone.
Edit
To do the same with a link button inside a template field, use the following code.
Use GridView_RowDataBound event to find Link button.
Dim LB as LinkButton = e.Row.FindControl("LinkButton1")
LB.Attributes.Add("href","../Test.aspx")
LB.Attributes.Add("target","_blank")
try by Adding following onClientClick event.
OnClientClick="aspnetForm.target ='_blank';"
so on click it will call Javascript function an will open respective link in News tab.
<asp:LinkButton id="lbnkVidTtile1" OnClientClick="aspnetForm.target ='_blank';" runat="Server" CssClass="bodytext" Text='<%# Eval("newvideotitle") %>' />
This is not perfect, but it works.
<asp:LinkButton id="lbnkVidTtile1" runat="Server"
CssClass="bodytext" Text='<%# Eval("newvideotitle") %>'
OnClientClick="return PostToNewWindow();" />
<script type="text/javascript">
function PostToNewWindow()
{
originalTarget = document.forms[0].target;
document.forms[0].target='_blank';
window.setTimeout("document.forms[0].target=originalTarget;",300);
return true;
}
</script>
LinkButton executes HTTP POST operation, you cant change post target here.
Not all the browsers support posting form to a new target window.
In order to have it post, you have to change target of your "FORM".
You can use some javascript workaround to change your POST target, by changing form's target attribute, but browser will give a warning to user (IE Does), that this page is trying to post data on a new window, do you want to continue etc.
Try to find out ID of your form element in generated aspx, and you can change target like...
getElementByID('theForm').target = '_blank' or 'myNewWindow'
When the LinkButton Enabled property is false it just renders a standard hyperlink. When you right click any disabled hyperlink you don't get the option to open in anything.
try
lbnkVidTtile1.Enabled = true;
I'm sorry if I misunderstood. Could I just make sure that you understand the purpose of a LinkButton? It is to give the appearance of a HyperLink but the behaviour of a Button. This means that it will have an anchor tag, but there is JavaScript wired up that performs a PostBack to the page. If you want to link to another page then it is recommended here
that you use a standard HyperLink control.
It throws error.
Microsoft JScript runtime error: 'aspnetForm' is undefined
<asp:LinkButton ID="LinkButton1" runat="server" target="_blank">LinkButton</asp:LinkButton>
Use target="_blank" because It creates anchor markup. the following HTML is generated for above code
<a id="ctl00_ContentPlaceHolder1_LinkButton1" target="_blank" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')">LinkButton</a>

Resources