Showing posts with label image. Show all posts
Showing posts with label image. Show all posts

Monday, March 26, 2012

Trouble Displaying Image in a User Control....

I am trying to add an image to my detail page without any success. I have a category page which displays items. You can choose an item which than going to the detail.aspx page displaying more information about the item. In the detail.aspx page the Page_Load event retrieves the ad number and puts it in a variable so I can retrieve that ad from the database. The Testad.ascx page is the user control with the logic I used for the detail.aspx page.

When I run this locally without trying to display an image it runs fine. The problem is displaying the image in the detail.aspx page. Below I entered what I thought would work. Can anyone take a good hard look at this and help get me on the right track.

At the very bottom I'm using the following to pull the image:

<IMG SRC='images/<%# Container.DataItem("ImageLabel") %>' Border="0"
Any opinions would be greatly appreciated.

Thank You.

I have included before detail.aspx and testad.ascx below.

===================================================
DETAIL.aspx PAGE...

<%@dotnet.itags.org. Register TagPrefix="ASPFD" TagName="Header" src="http://pics.10026.com/?src=header.ascx" %>
<%@dotnet.itags.org. Register TagPrefix="ASPFD" TagName="TestAd" src="http://pics.10026.com/?src=Testad.ascx" %>
<HTML>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
If Not IsPostBack Then
Dim AdNumSent As Integer

If Trim(Request.QueryString("AdNum")) = "" Then
Response.Redirect("default.aspx")
End If

Header.AddPageName("Ad Detail")

AdNumSent = Trim(Request.QueryString("AdNum"))
TestAd.GetAd(AdNumSent)

End If
End Sub
</script>
<body vlink="red">
<form runat="server">
<aspfd:header id="Header" runat="server" />
<aspfd:testad id="testAd" runat="server" />
</form>
</body>
</HTML
===================================================

TESTAD.ascx Page...

<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim ConnectString, SelectStatement As String
Dim Connect As OleDbConnection = New OleDbConnection
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter
Dim TestCB As OleDbCommandBuilder
Dim TestDS As DataSet = New DataSet
Dim Row As DataRow

Public AdNum As Integer
Public Title As String
Public Description As String
Public Category As String
Public Price As String
Public Phone As String
Public Email As String
Public State As String
Public Posted As Date
Public Password As String
Public Image As String

Public HasErrors As Boolean
Public RowError As String

Sub GetAd(AdNumSent As Integer)
SelectStatement = "Select * From Ads Where AdNum=" & AdNumSent
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("Testdb.mdb") & ";"
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = new OleDbCommand(SelectStatement, Connect)
Adapter.Fill(TestDS,"Ads")
TestCB = New OleDbCommandBuilder(Adapter)

If TestDS.Tables("Ads").Rows.Count > 0 Then
Row = TestDS.Tables("Ads").Rows(0)

AdNum = Row.Item("AdNum")
Title = Row.Item("Title")
Description = Row.Item("Description")
Category = Row.Item("Category")
Price = Row.Item("Price")
Phone = Row.Item("Phone")
Email = Row.Item("Email")
State = Row.Item("State")
Posted = Row.Item("Posted")
Password = Row.Item("Password")
Image = Row.Item("Image")

TitleLabel.Text = Title
DescriptionLabel.Text = Description
PriceLabel.Text = Price
PhoneLabel.Text = Phone
EmailLink.Text = Email
EmailLink.NavigateURL = "mailto:" & Email
StateLabel.Text = State
PostedLabel.Text = Posted
ImageLabel.Text = Image
End If

PostErrors
End Sub

Sub PlaceAd
Row = TestDS.Tables("Ads").NewRow

CopyToDS
Row.Item("Posted") = CDate(Today)
TestDS.Tables("Ads").Rows.Add(Row)
Adapter.Update(TestDS, "Ads")
PostErrors
End Sub

Sub EditAd
CopyToDS
Adapter.Update(TestDS, "Ads")
PostErrors
End Sub

Sub DeleteAd
TestDS.Tables("Ads").Rows(0).Delete
Adapter.Update(TestDS, "Ads")
PostErrors
End Sub

' Copy the values in the properties of this
' control in the TestDS
Private Sub CopyToDS
Row.Item("Title") = Title
Row.Item("Description") = Description
Row.Item("Category") = Category
Row.Item("Price") = CSng(Price)
Row.Item("Phone") = Phone
Row.Item("Email") = Email
Row.Item("State") = State
Row.Item("Password") = Password
Row.Item("Image") = Image
End Sub

Private Sub PostErrors
HasErrors = TestDS.HasErrors
If HasErrors Then
RowError = TestDS.Tables("Ads").Rows(0).RowError
End If
End Sub
</script>
<asp:datalist id="DataList1" runat="server"></asp:datalist>
<TABLE id="Table1" cellSpacing="0" cellPadding="2" width="100%" bgColor="lime" border="1">
<tr>
<td bgColor="yellow" colSpan="2"><asp:label id="TitleLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td vAlign="top" width="25%">Description:</td>
<td><asp:label id="DescriptionLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Price:</td>
<td>$<asp:label id="PriceLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label>
</td>
</tr>
<tr>
<td width="25%">Phone:</td>
<td><asp:label id="PhoneLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Email:</td>
<td><asp:hyperlink id="EmailLink" runat="server" font-bold="true" font-size="12 pt"></asp:hyperlink></td>
</tr>
<tr>
<td width="25%">Location:</td>
<td><asp:label id="StateLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Posted Date:</td>
<td><asp:label id="PostedLabel" runat="server" font-bold="true" font-size="12 pt"></asp:label></td>
</tr>
<tr>
<td width="25%">Image:</td>
<td><IMG SRC='images/<%# Container.DataItem("ImageLabel") %>' Border="0"></td>
</tr>
</TABLE>Anyone have any idea??????
You forgot to DataBind()
Bleroy,

If I run the code without trying to pull an image it works and I didn't Data Bind() it. When an image is add into the mix do you have to Data Bind()? Is an image handled different?

Thanks.
A help would be apprieciated. This is really frustrating me. grrrr
What does ImageLabel contain? What do you see when you look at the client-side HTML?

Trouble getting jpg to display in image control

Hi,

My company is changing its logo and I am having trouble getting my
existing image controls in asp.net apps to read the new jpg. I do not
need to programmatically change them, as they are static, but when
using the new jpegs I only get the little red x. I have added the new
jpg to the project, I can see it right there when I go to set the
image url of the control, and when I double click from the solution
explorer it displays properly in Photo Editor but no luck in my
control. Creating new controls and changing existing ones produces
the same result. I am able to use a new gif, but I am unhappy with
the image quality.

Any suggestions would be great.You'll want to make sure that the URL isn't pointing to your local file
system (file:) rather than a regular IIS url.

Also, is this inside the firewall? Are you using the same filename for the
new image?

Some intranets have very aggressive caching. You might defeat it by
changing the name of the .jpg if you haven't already tried that. Or ask the
security admin to dump the cache.

Just tossing out some ideas....

"Brian Hanson" <bdhanson@.mcdermott.com> wrote in message
news:169b400f.0312010828.2ad4bcb9@.posting.google.c om...
> Hi,
> My company is changing its logo and I am having trouble getting my
> existing image controls in asp.net apps to read the new jpg. I do not
> need to programmatically change them, as they are static, but when
> using the new jpegs I only get the little red x. I have added the new
> jpg to the project, I can see it right there when I go to set the
> image url of the control, and when I double click from the solution
> explorer it displays properly in Photo Editor but no luck in my
> control. Creating new controls and changing existing ones produces
> the same result. I am able to use a new gif, but I am unhappy with
> the image quality.
> Any suggestions would be great.

Thursday, March 22, 2012

Trouble with Inline If Syntax on asp Image

I have the following asp image, but I'm a little off on the syntax. Could you help. Thanks

<asp:ImageID="RecipeImage"runat="server"Width="176px"Height="115px"ImageUrl='<% (Eval("RecipeID") !=Null) ? "Pictures/recipes/" + Eval("RecipeID") + ".jpg" : "~/Pictures/recipes/NoPhoto2.jpg" %>'/>

why not populate it from the codebehind? IT would be easier... otherwise, wrap a function around it and use that.


I was going to populate it in codebehind based on the querystring id, but i can't because i'm using a pager template and the querystring id is only the id i want one time.

If I use a function, how can I access the Current Id in the FormView?

trouble with image

Hi guys,
I'm a beginner of asp.net:( When I click a
(System.Web.UI.WebControls.)Button on a page,of course,its' click event has
been assigned,the images on this page should be refreshed,right?These
images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
happen,why?
Much thanx.Presumably because the browser has cached the image that was at that
URL previously. If you want to load a different image for each screen
refresh then add a random number, or datestamp to the URL for your
image, that way the browser receives a different URL and will
redownload the image.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
news:1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
>
For a production environment, where the image may not change much, then I
would recommend removing the auto-generated number so that the cache
displays the image. Otherwise, the client may download more than it needs
too...<shrug>
Mythran
Thanx for your advice.My current problem: in the button click event,picture
stored in db is changed. "GetPic.aspx?id=xxx" is used to get pic from
db.What I want is after click,the image on this page should display the new
content(reload from db).But now db has updated successfully,the page is
still here,no change.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com>
':1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
>
"removing the auto-generated number so that the cache displays the image"
Sorry but I have no idea how to remove,thanx.
"Mythran" <kip_potter@.hotmail.comREMOVETRAIL>
':eeIMsezVGHA.5044@.TK2MSFTNGP09.phx.gbl...
> "Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
> news:1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> For a production environment, where the image may not change much, then I
> would recommend removing the auto-generated number so that the cache
> displays the image. Otherwise, the client may download more than it needs
> too...<shrug>
> Mythran
>
Much thanx,Flinky Wisty Pomm && Mythran:)
I got it,add a RequiredFieldValidator on the page and bind it to any
control,then nothing bother me:) But who can tell me why?puzzling
"tjer" <tj@.tj.edu.cn> д?:#jIoo1xVGHA.5288@.TK2MSFTNGP14.phx.gbl...
> Hi guys,
> I'm a beginner of asp.net:( When I click a
> (System.Web.UI.WebControls.)Button on a page,of course,its' click event
has
> been assigned,the images on this page should be refreshed,right?These
> images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
> happen,why?
> Much thanx.
>

trouble with image

Hi guys,

I'm a beginner of asp.net:( When I click a
(System.Web.UI.WebControls.)Button on a page,of course,its' click event has
been assigned,the images on this page should be refreshed,right?These
images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
happen,why?

Much thanx.Presumably because the browser has cached the image that was at that
URL previously. If you want to load a different image for each screen
refresh then add a random number, or datestamp to the URL for your
image, that way the browser receives a different URL and will
redownload the image.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
news:1144079199.958679.87150@.v46g2000cwv.googlegro ups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.

For a production environment, where the image may not change much, then I
would recommend removing the auto-generated number so that the cache
displays the image. Otherwise, the client may download more than it needs
too...<shrug
Mythran
Thanx for your advice.My current problem: in the button click event,picture
stored in db is changed. "GetPic.aspx?id=xxx" is used to get pic from
db.What I want is after click,the image on this page should display the new
content(reload from db).But now db has updated successfully,the page is
still here,no change.

"Flinky Wisty Pomm" <Pathogenix@.gmail.com>
??:1144079199.958679.87150@.v46g2000cwv.googleg roups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
"removing the auto-generated number so that the cache displays the image"

Sorry but I have no idea how to remove,thanx.

"Mythran" <kip_potter@.hotmail.comREMOVETRAIL>
??:eeIMsezVGHA.5044@.TK2MSFTNGP09.phx.gbl...
> "Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
> news:1144079199.958679.87150@.v46g2000cwv.googlegro ups.com...
> > Presumably because the browser has cached the image that was at that
> > URL previously. If you want to load a different image for each screen
> > refresh then add a random number, or datestamp to the URL for your
> > image, that way the browser receives a different URL and will
> > redownload the image.
> For a production environment, where the image may not change much, then I
> would recommend removing the auto-generated number so that the cache
> displays the image. Otherwise, the client may download more than it needs
> too...<shrug>
> Mythran
Much thanx,Flinky Wisty Pomm && Mythran:)

I got it,add a RequiredFieldValidator on the page and bind it to any
control,then nothing bother me:) But who can tell me why?puzzling

"tjer" <tj@.tj.edu.cn> д?:#jIoo1xVGHA.5288@.TK2MSFTNGP14.phx.gbl ...
> Hi guys,
> I'm a beginner of asp.net:( When I click a
> (System.Web.UI.WebControls.)Button on a page,of course,its' click event
has
> been assigned,the images on this page should be refreshed,right?These
> images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
> happen,why?
> Much thanx.

Trouble with paths in Style Sheets

Consider the following style declaration in a stylesheet:


background-image: url('path/to/image');

That's really all I'm trying to accomplish, but I'm running into difficulties using Visual Studio 2005 on my ASP page.

The problem is that I'm unable to find a good way to refer to the "document root" within those 'url' attributes in the stylesheet. I understand I could use the '~' mark, in an asp.net control, to refer to the document root, but it doesn't work within the 'url' declaration in a stylesheet. Also, simply using '/' doesn't work, since that ends up referring to a directory much higher up in the directory structure, something like my C: drive.


The solutions I've found are to do something like "url(../path/to/images)". That works, but it's ugly, and I'd like to base the paths on the document root, not the directory my stylesheet happens to be in.


I can also include the entire full path to the image directory, relative to my C: drive, but that's even worse, and it won't work once the site is published.

So, is there a "DOCUMENT_ROOT" type of value I can use, or can I set the document root behavior for a given website in Visual Studio?

Thanks.

Have you tried background-image: url('/path/to/image');? I think just having the first slash will take it to the docuemnt root. I could be wrong though.


Having just the first slash doesn't work. I'm not sure where the "/" brings it, but I think it's probably going back to the root of my hard drive. In either case, it's not finding the proper path that way.

It comes down to there being a disconnect between the way web pages function (where "/" should bring you to the root of the site) and the way Visual Studio treats things (where "/" seems to bring it to the filesystem room, instead of the root for that particular website/project.

Is there a way to convince Visual Studio to see "/" as the root for that website, instead of some place further up the directory structure?


this may not be useless to remind that relative pathes in external stylesheet MUST be RELATIVE to the very CSS file itself. (Obvious since the same css file can be linked by many remote pages)therefore url(../path/to/images) is not so ugly ;-)Using absolute path, one can try to concatenate with Request.ApplicationPath & "path/to/image/"...

With Request.ApplicationPath, I think that would only work in a .aspx file, not in a .css file, but I'll see if it does anything.


hum... using aspx for css file would prevent the web designer to edit it. I would rather have the css file next to the image directory and use relative path into the css. the page only needs to know wher the css is.

It turns out all I needed to do was to modify the "Virtual Path" property on the website, to "/" instead of "/MySiteName". The reason I didn't notice this was because I didn't have SP1 installed, and it's not available in the normal, installed version.

Thanks for the suggestions.

Tuesday, March 13, 2012

Troubles with using a user control

Im using a Top Navigation Bar Web control in my application.
This Bar uses Images. Im trying to dynalically assign the relative URL
path as image path. That is, a particular image can have src attribute
as "../../images" or "images/" etc based on a public property of
control, callingDepth. This property is set in control delaration in
aspx page.
Im using src="http://pics.10026.com/?src=<% #fixRelPath("Images/med_upper_left1.gif") %> function
call in the ASPx pages.
The problem is that this function is not at all called all through page
load.
Any Clue on what i'm missing.
Thanks for Help.Expressions surrounded by <% # and %> are evaluated when the control
is DataBound. So you need to call the DataBind on the object, or a
container of that object.
For more info on DataBinding Expressions, see
http://www.dotnetjunkies.com/quicks...atabinding.aspx

Troubles with using a user control

Im using a Top Navigation Bar Web control in my application.
This Bar uses Images. Im trying to dynalically assign the relative URL
path as image path. That is, a particular image can have src attribute
as "../../images" or "images/" etc based on a public property of
control, callingDepth. This property is set in control delaration in
aspx page.
Im using src="http://pics.10026.com/?src=<% #fixRelPath("Images/med_upper_left1.gif") %> function
call in the ASPx pages.
The problem is that this function is not at all called all through page
load.
Any Clue on what i'm missing.
Thanks for Help.Expressions surrounded by <% # and %> are evaluated when the control
is DataBound. So you need to call the DataBind on the object, or a
container of that object.

For more info on DataBinding Expressions, see
http://www.dotnetjunkies.com/quicks...atabinding.aspx