Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

writing parameter dynamically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Adam Right - 10 Feb 2008 02:04 GMT
Hi All

How can i write dynamic parameter for a java script function in<asp:image>
tag?

for static usage  like ;
onmouseover="ChangePicture('images/blue.gif')"
works fine.

I have to use single quotes because the parameter must be string. If i try
like that;

onmouseover='<%# "ChangePicture('" + Eval("BIG_PICTURE_PATH") + "')" %>'

it raises  "The server tag is not well formed" error ....

What should I do?

Thanks,

Adam
Nathan Sokalski - 10 Feb 2008 03:05 GMT
Try something like the following:

'<%#
DataBinder.Eval(Container.DataItem,"BIG_PICTURE_PATH","ChangePicture('{0}');")
%>'

This databinding expression uses a format string as the third parameter. I
usually find it easier to use simple format strings like this when I want to
include other text along with the value being databound (there are less
quotes that get nested inside of each other, as well as making the need for
concatenation much less common). For more details on databinding expressions
and format strings, see the documentation.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Hi All
>
[quoted text clipped - 17 lines]
>
> Adam
Adam Right - 10 Feb 2008 11:50 GMT
Hi Nathan,

It does not work, still same problem..
the single quotes in '{0}' causes the error "The server tag is not well
formed" error ,
if i remove the single quotes no error occurred but function gets error...
S. Justin Gengo - 10 Feb 2008 12:54 GMT
Adam,

You should be able to use double quotes instead of single quotes around the
{0} but you'll have to double up the double quotes like this: ""{0}""

Regards,

S. Justin Gengo

Free code and component libraries at:
http://www.aboutfortunate.com

> Hi Nathan,
>
> It does not work, still same problem..
> the single quotes in '{0}' causes the error "The server tag is not well
> formed" error ,
> if i remove the single quotes no error occurred but function gets error...
Nathan Sokalski - 10 Feb 2008 17:02 GMT
What is the complete code for the tag in the *.aspx file? When I use things
the way I showed you, even with single quotes, they work perfectly. What is
the complete exact text of the error message? I am wondering if it is
possible that the error is referring to a different server tag.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Hi Nathan,
>
> It does not work, still same problem..
> the single quotes in '{0}' causes the error "The server tag is not well
> formed" error ,
> if i remove the single quotes no error occurred but function gets error...
Jose A. Fernandez - 10 Feb 2008 17:59 GMT
Hello Adam

With a htmlcontrol img (tag <img .. />
    <asp:FormView ID="FormView1" runat="server"...
        <ItemTemplate>...
             <img src="/images/image1.jpg" onmouseover="<%#
String.Concat("ChangePicture('", Eval("BIG_PICTURE_PATH"), "');") %>" /

the render is
     <img src="/images/image1.jpg" onmouseover="ChangePicture('/
images/OtherImage.jpg');" />

But, if you have webcontrol Image...
   <asp:FormView ID="FormView1" runat="server"...
        <ItemTemplate>...
              <asp:Image runat="server" ID="imgExample" ImageUrl="~/
images/image1.jpg" />

and into codebehind, in ItemCreated method
    Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal
e As System.EventArgs) Handles FormView1.ItemCreated

       Dim pathImagen As String = CType(FormView1.DataItem,
Data.DataRowView).Item("CategoryID").ToString
       Dim imgExample As Image =
CType(FormView1.FindControl("imgExample"), Image)

       imgExample.Attributes.Add("onmouseover", "ChangePicture('" &
pathImagen & "');")

   End Sub

the render id
 <img id="ctl00_contenidoCentral_FormView1_imgExample"
onmouseover="ChangePicture('/images/OtherImage.jpg');" src="../images/
image1.jpg" ...

Links
--------------
WebControl.Attributes Property
Gets the collection of arbitrary attributes (for rendering only) that
do not correspond to properties on the control.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.at
tributes(VS.80).aspx


______________________
Jose A. Fernandez
blog: http://geeks.ms/blogs/fernandezja

> What is the complete code for the tag in the *.aspx file? When I use things
> the way I showed you, even with single quotes, they work perfectly. What is
[quoted text clipped - 10 lines]
> > formed" error ,
> > if i remove the single quotes no error occurred but function gets error...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.