> I'm facing this problem I have images on my website but when I Deploye
> the website on server the Images are not there I only get the X sign.
> How can I go about this.
By making sure that the images are where the rest of the app is expecting to
find them...
Why are they not there...? Have you forgotten to deploy them to the
website...? Are you using absolute addressing when you should be using
relative addressing...?
And to test this, see the properties of such a failed image (or find it in
the
html-source of the page in the browser). Is the URL what you expect it to
be? Are the images really where that URL is pointing to?
Hans Kesting
Thanks Hans,
I have managed to see it on The server But when I try getting the
website on The Client I can't see Images. what could i do?
Thanks.
> I have managed to see it on The server But when I try getting the
> website on The Client I can't see Images. what could i do?
Ah... you surely haven't hardcoded the full filespec of the image files,
have you...?
E.g. <img src="C:\Inetpub\wwwroot\MyProject\images\logo.jpg" />
Thanks,
Is it any different? I'm using ImageUrl.
ImageUrl="file:///C:\Inetpub\wwwroot\MyProject\Images\logo.JPG "
Thanks
It's the same thing - this is never going to work...
Use relative addressing for all your images.
If MyProject is a name of the virtual root, you can represent it (the
root path) with a tilda (~) character.
~/Images/logo.JPG
If the web form is located in C:\Inetpub\wwwroot\MyProject\
you can use
Images/logo.JPG
> Could you please help me and show a simple example how to use relative
> addressing?
Rocco,
> I have just tried it but it ain't working this is how I've just tried
> it: ImageUrl="file:///C:\Inetpub\wwwroot\Images\logo.JPG".
You cannot hard-code the absolute path like this!!!
Not sure why you seem to be finding this so difficult to understand...
Imagine your site has the following structure (FORGET TOTALLY ABOUT
C:\Inetpub\wwwroot !!!)
<root>
\bin
\Properties
\References
\Folder1
File1.aspx
File2.aspx
\Folder2
File3.aspx
File4.aspx
\images
logo.jpg
\master
default.master
default.aspx
Global.asax
web.config
You are editing \Folder1\File1.aspx and want to include a link to your
logo - do this:
ImageUrl="../images/logo.jpg"
or
ImageUrl="~/images/logo.jpg"
and what about TILDA?
http://en.wikipedia.org/wiki/Tilde
> Even tilda does not show any Image.
Do a View Source and look at the URL that ASP.NET has created - what does it
say...?
It says: <img id="Logo2" src="../Images/logo.JPG".
Thanks.
Cool! Now we're getting somewhere - you're finally using relative
addressing - hurrah!
So, is the above source actually correct relative to the folder that the
ASPX is in...?
Yes it is.
Hi,
I was wondering does it matter where I place the folder with the
Images could it be the problem?
Thanks.
> I was wondering does it matter where I place the folder with the
> Images
Of course it does!!!
They are next to the Bin folder hope I'm not doing a mistake!
Thanks
Oh dear... The important thing here is the depth of the folder in relation
to the root.
Once again...
Imagine your site has the following structure (FORGET TOTALLY ABOUT
C:\Inetpub\wwwroot !!!)
<root>
\bin
\Properties
\References
\Folder1
File1.aspx
File2.aspx
\Folder2
File3.aspx
File4.aspx
\Folder3
File5.aspx
\images
logo.jpg
\master
default.master
default.aspx
Global.asax
web.config
You are editing \Folder1\File1.aspx and want to include a link to your
logo - do this: ImageUrl="../images/logo.jpg"
However, that wouldn't work for File5.aspx because it is at a different
depth relative to the root. For File5.aspx, you'd need to do:
ImageUrl="../../images/logo.jpg"
Parent paths are disabled by default in IIS 6.0 and can be disabled on
IIS 5 as well.
Why don't you use
ImageUrl="/images/logo.jpg"
That path will always work, with no depends where the aspx is located.
All right. Good to know
On the server you should have the same configuration as on the
localhost. Namely,
1) the aspx page is in the root directory
2) the root directory has /images
3) logo.JPG is in the /images
> I have just realised my stupid mistake, I wasn't deploying the Image
That was the very first thing I asked you in my first reply to your original
post back on 30th March...
System.Web.UI.WebControls.RadioButtonList st5=new
System.Web.UI.WebControls.RadioButtonList();
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl("rblmood");
System.Web.UI.WebControls.Image imgDaily=new
System.Web.UI.WebControls.Image();
imgDaily=(System.Web.UI.WebControls.Image)e.Item.Cells[1].FindControl("imgbm");
myCommand.Parameters.Add(new SqlParameter("@MoodToday",SqlDbType.Char,
45));
if(e.Item.Cells[1].Equals("Bad Mood"))
{
imgDaily.ImageUrl = "imgbm";
}
else
{
imgDaily.ImageUrl = "imggm";
}
myCommand.Parameters["@MoodToday"].Value=st5.SelectedValue;
My problem is that only goog mood appears but the image imggm does not
does not appear how should I do it.
Thanks
>From the code above you cannot see if e.Item.Cells[1] equals the "Bad
Mood" or not. I'm also confused about
e.Item.Cells[1].FindControl("imgbÂm");
It used the same cell of the grid. If cell[1] contains a control named
"imgbÂm", it cannot be equal to the "Bad Mood"
"Imgbm" cannot be a name of an image and you cannot use it as a value
for the ImageUrl property.
e.Item.Cells[1] cannot be equals to "Bad Mood". If "Bad Mood" is a
value of a radiobutton, then you should compare the value of the
radiobutton
if(st5.SelectedValue == "Bad Mood") {
...
} else {
...
}
Start the application in Debug Mode and check the values.
st5 is your RadioButtonList
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl(Â"rblmood");
so, what do you want to get using
st5.SelectedValue="Images/laughing.gif";
?
Sorry I've been away for some time. Yes st5 is my RadioButtonList. I
want the image laughing to come along when good mood is selected.
that's: st5.SelectedValue="Images/laughing.gif";
Thanks.
1) SelectedValue is a read-only property and you cannot assign a value
using st5.SelectedValue=...
2) st5 is a RadioButtonList and it cannot be equal to the "Images/
laughing.gif"
Is that the reason I'm getting this error:
Specified argument was out of the range of valid values. Parameter
name: Images/laughing.gif ?
Thanks
Wait, I think I made a mistake telling that it's a read-only:
MSDN: "Gets the value of the selected item in the list control, or
selects the item in the list control that contains the specified
value."
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Sorry.
The error message "Specified argument was out of the range of valid
values. Parameter name: Images/laughing.gif" means that there is no
such value "Images/laughing.gif".
> 1) SelectedValue is a read-only property
No it isn't...
I had already replied on this
Sorry - your reply hadn't arrived when I posted...
How can I make it work? Please help me.
thanks
Mark, no problem, actually I don't know why I thought it's a read-only
property. Maybe I had never used that before.
Rcoco,
You should understand conceptually what you are doing, rather than
following copy-and-paste code blindly. Your program is working as you
designed it, and not as you might think it should work.
You have to understand what the "out of the range of valid values"
means. This means that st5 (a RadioButtonList) has no value named
"Images/laughing.gif". I cannot answer, how you can make it working,
because I don't know how it should work. You used the following code
before:
imgDaily.ImageUrl = "imgbm"
Now, you are using
st5.SelectedValue = "..."
Why did you change this and what is the logic behind?
I thought, you wanted to change an image. Using st5.SelectedValue you
will change selection (a point) of the radio button.
If you definitely need to change the selected item in the
RadioButtonList you should know what values it has. Look in your code
where you bind the values (dataset, whatever) to this control.
P.S.
If you don't get what I mean, once again post the complete source code
of your radio button list which is not working as expected (aspx part
and code-behind) and explain how it should work step by step.
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
Fill();
Bind();
}
}
System.Web.UI.WebControls.RadioButtonList st5=new
System.Web.UI.WebControls.RadioButtonList();
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl("rblmood");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into DashBoard (MoodToday) values
(@MoodToday)";
myCommand.Parameters.Add(new
SqlParameter("@MoodToday",SqlDbType.Text));
myCommand.Parameters["@MoodToday"].Value=st5.SelectedValue;
if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="images/sad.gif";
}
else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="images/laughing.gif";
}
Fill();
InsertEmpty();
Bind();
This is the HTML part
<ItemTemplate>
<asp:Label id=Label2 runat="server" Width="104px" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>'>Label</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/laughing.gif"
ImageAlign="Right"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"
ImageAlign="Right"></asp:Image>
</EditItemTemplate>
Thanks
What do you mean by "the image should be selected"?
Assuming the code is working properly, except a "selection" of the
image, you should change the if..else block
Image imggm = (Image)e.Item.Cells[1].FindControl("imggm");
Image imgbm = (Image)e.Item.Cells[1].FindControl("imgbm");
if (st5.SelectedValue == "Bad Mood")
{
imgbm.BorderWidth = Unit.Pixel(2);
} else {
imggm.BorderWidth = Unit.Pixel(2);
}
This code put a border around the first image if st5.SelectedValue !=
"Bad Mood", otherwise, the second image will be bordered. This is how
I understand your "selection".
Hope, it helps.
<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="112px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/
laughing.gif"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"></
asp:Image>
</EditItemTemplate>
Thanks
I don't get your reply.
What problem do you have? An image sad.gif is not shown? If yes, when
the problem occurs, when page is initially loaded or after you changed
a selection of the RadioButtonList?
It's supposed to work like this When on selection of RadioButton from
RadioButtonList and inserts data that is when Image should be visible
in datagrid column. For example if Bad Mood is selected and inserted
into database, image sad.gif should be visible in datagrid column:
))(( Bad Mood (consider ))(( to be image sad.gif).
This should be after one has inserted data.
Thanks
Thanks.
Alexey,
What if I Change the images from EditItemTemplate to ItemTemplate
wouldn't it be better? As in I make the images invisible and When I
edit my data in datagrid one of the images becomes visible can tha
work?
Thanks
But then I think it has nothing to do with the EditItemTemplate
If I understand you correct, you have to change
<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/
laughing.gif"
ImageAlign="Right"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"
ImageAlign="Right"></asp:Image>
</EditItemTemplate>
to:
<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>
and delete the following part
if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="images/sad.gif";
}
else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="images/laughing.gif";
}
The EditItemTemplate used to edit a current record in the datagrid.
That is:
1) you bind your grid to the database
2) you show EditItemTemplate with your radio buttons
3) you post the web form back to the server
4) you find a selected value of the radio button
<-- I guess, you are this step
5) you save the selected value to a database
6) you bind your grid to the database again
So, you should update the database (step #5) and repeat step #1 which
is the same to step #6
How to with a DataGrid
http://www.google.com/search?hl=en&q=datagrid+tutorial+asp.net
But after updating the datagrid how can I make one I mage visible?
Thnks
You are right, I forgot to mention.
You can have an additional column in your datagrid, where you will
show your "mood".
I'm not sure what exactly you kept in the database as a "mood" value:
a string, or numeric value?
If you kept a string in the database ("sad", or "laughing")
the code will be
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
DataBinder.Eval(Container.DataItem, "Mood") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
where Mood is a name of your datasource field
If you save your mood as a numeric value (e.g. "0" - for sad, "1" -
for "laughing")
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((int)DataBinder.Eval(Container.DataItem, "Mood") == 0 ? "sad" :
"laughing") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
Seems not working I'm i getting it right?
<ItemTemplate>
<asp:Label id=Label2 runat="server" Width="97px" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>'>Label</asp:Label>
<asp:Image id=imgbm runat="server" ImageUrl='<%# "/Images/"
+DataBinder.Eval(Container.DataItem, "MoodToday") + "../Images/
sad.gif"%>' Visible="False">
</asp:Image>
<asp:Image id=imggm runat="server" ImageUrl='<%# "/Images/"
+DataBinder.Eval(Container.DataItem, "MoodToday") + "../images/
laughing.gif"%>' Visible="False">
</asp:Image>
</ItemTemplate>
Thanks
ImageUrl='<%# "/Images/" +DataBinder.Eval(Container.DataItem,
"MoodToday") + "../Images/sad.gif"%>'
Using the code above, what URL are you expecting to get in the output?
I want to get Sad.gif when its Bad mood that was selected.
thanks
I will rephrase the question:
"/Images/" + {something} + "../Images/sad.gif" = ?
that's for getting the ImageUrl .
Alexey,
You gave this example and I've just nrealised that actually I did not
understand it:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
DataBinder.Eval(Container.DataItem, "Mood") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
Could you try to explain to me please?
I understand that you don't understand. But you have to understand
that "A"+"B" = "AB".
The goal is to show an image, which is located somewhere on a server.
I don't know exactly what url does your image, but I suppose it is
something like this
/Images/laughing.gif
/Images/sad.gif
To check if I'm right (and the url is right) type that url in the
address bar of your browser.
For example:
http://servername/Images/laughing.gif
http://localhost/Images/laughing.gif (if you do it locally)
You should see an image.
If you don't see it - the url is wrong, and you have to find the right
url.
A: What is the right url?
Now, when we know an url, we come to another question: what value do
you have in the database.
MoodToday is.... a number, a string.... ? what?
Assuming it is a string.
Assuming it is either "sad", or "laughing".
B: What is the value of MoodToday?
Please answer these 2 questions for me and we could finally check if
"A"+"B" = "AB"
The right URL is http://localhost/Images/laughing.gif,
Mood today is a string, the value of Mood Today is text 16
Thanks
I forgot the value that are in MoodToday are Good Mood & Bad Mood.
Thanks
No offense, but how in the world are you a .NET developer yet don't
understand such a simple concept as relative address of an HTML image?
:-)
I am staggered at Alexey's patience with this guy - I gave up days ago...
I'd hate to be his boss!
Okay, going back to the code I sent you some time ago:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" :
"laughing") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
The code above would show one of two images:
MoodToday = "Bad Mood" ---> /images/sad.gif
otherwise ---> /images/laughing.gif
If you will have any problem with that Image Control you should debug
your code.
It could be done, e.g. like the following example:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" :
"laughing") + ".gif" %>'/>
Current Mood in the database is: <%#
DataBinder.Eval(Container.DataItem, "MoodToday") %>
Image URL is: <%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" :
"laughing") + ".gif" %>
</ItemTemplate>
</asp:TemplateColumn>
I hope I didn't make any mistake and my code will work for you and we
finally close the issue with images :-)
The author deserve admiration for his persistence and stubbornness :-)
> The author deserve admiration for his persistence and stubbornness :-)
That's one way of looking at it...!
I get the error Specified cast is not valid at run time.
And when I changed the code to
<asp:Image id=Image1 runat="server" ImageUrl='<
%#DataBinder.Eval(Container.DataItem,"MoodToday")=="Bad
Mood"?"sad":"laughing" )+".gif"%>' Visible="True">
</asp:Image>
Only the Image laughing .gif appears whether Good Mood or Bad Mood is
selected.
Why is it so?
Have you tried to debug it?
Put this line as I already told you
Current Mood in the database is: ***<%#
DataBinder.Eval(Container.DataItem, "MoodToday") %>***
If you believe that a "Bad Mood" is selected (it has to be saved(!))
then you will see
***Bad Mood***
Otherwise you will see
***Good Mood***
***abracadabra***
******
and so on
Sorry again Every thing was going on well but all of a sudden I got a
wired reaction:
Why is it that when I insert data I fast get an error :
Specified cast is not valid.
But When I run the site for the second time I find the data was saved
the right image was selected! Actually I can say every thing works
well apart that when ever I attempt to insert data this error appears:
Specified cast is not valid. on line:
<asp:Image id=Image1 runat="server" ImageUrl='<%#"/Images/"+
((string)DataBinder.Eval(Container.DataItem,"MoodToday")=="Bad
Mood"?"sad":"laughing") +".gif"%>' ImageAlign="Middle">.
Thanks
Actually the error reads: System.InvalidCastException: Specified cast
is not valid.
and the stack Trace
[InvalidCastException: Specified cast is not valid.]
ASP.DashBoard_aspx.__DataBind__control16(Object sender, EventArgs
e) in c:\inetpub\wwwroot\Dash_Board\DashBoard.aspx:46
System.Web.UI.Control.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex,
Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object
dataItem, DataGridColumn[] columns, TableRowCollection rows,
PagedDataSource pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
Dash_Board.DashBoard.Bind() in c:\inetpub\wwwroot\dash_board
\dashboard.aspx.cs:109
Dash_Board.DashBoard.dgis_ItemCommand(Object source,
DataGridCommandEventArgs e) in c:\inetpub\wwwroot\dash_board
\dashboard.aspx.cs:176
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args)
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
Help me please.
Thanks