Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please help me define a variable in the HTML of my .NET page

    Hi everyone,

    I am trying to retrieve a value from a datalist control and store it in a variable. The tag that I am using to get the value is in the ItemTemplate area of my control. It looks like this:

    <%# DataBinder.Eval(Container.DataItem, "Name") %>

    My question: is there a way to create a variable that I can use in my HTML area of my .Net program that can then be used else ware on the page. My goal is to send the variable to a javascript after loading it with a value from the DataItem.

    Your help would be greatly appreciated.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You're only expecting one row, not anything repeated?
    Or ...?

    This sounds more like a classic ASP way of looking at things than a .NET way of looking at things. Can you be more clear about what you're trying to do?

    onItemDataBound fires for repeaters.
    http://msdn2.microsoft.com/en-us/lib...databound.aspx

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The control that Iím using has some characteristics like a repeater control but it is a DataList control. It does repeat rows like a repeater control but what I want to do is this. When my user clicks on one image, I want to send the path or name of that image to a JavaScript. Inside the JavaScript, I should be able to have the image loaded in JavaScript at this point. Iím getting my images, name and path from my DataList control

    This is the line of code that Iím using to send the name as a parameter to javascript but it is sent as a string that looks like thisÖ

    <%# DataBinder.Eval(Container.DataItem, \"Name\")%>

    instead of the actual name of the image. I am hoping that I can dump the name of the image in a variable and send the variable instead. Hereís the line of code that Iím using to do this.

    <asp:HyperLink id=Hyperlink1 runat="server" NavigateUrl='JavaScriptpenPopup("largerImage.aspx?name=<%# DataBinder.Eval(Container.DataItem, \"Name\")%>")' ImageUrl='<%# "../images/" + DataBinder.Eval(Container.DataItem, "ImagePath") %>'>
    </asp:HyperLink>

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That looks close, but I think you have your quotes a bit off.
    Try this.

    Code:
    <asp:HyperLink 
    id="Hyperlink1"
    runat="server" 
    NavigateUrl="javascript:OpenPopup('largerImage.aspx?name="+<%# DataBinder.Eval(Container.DataItem, "Name")%>+"');"
    ImageUrl="../images/" + <%# DataBinder.Eval(Container.DataItem, "ImagePath") %>
    / >
    Assuming OpenPopup is a defined javascript function.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi I got a "Server tag not well formed" error. I am working in VB.NET so I took our the ";" that was in one of the tags. Here is what i have now and I'm still getting the error. I also tried removing the slash that's at the end of the DataBinder.Eval(). Still the same error. Hrere's what I have now:

    <asp:HyperLink id="Hyperlink1"runat="server" NavigateUrl="javascript:OpenPopup('largerImage.aspx?name="+<%# DataBinder.Eval(Container.DataItem, "Name")%>+"') "ImageUrl="../images/" + <%# DataBinder.Eval(Container.DataItem, "ImagePath") %>/></asp:HyperLink>

    I've tried a number of things like replacing the quotes with &quote; but still the same error.

    I really appreciate you help,

    Alex

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Ditch the end tag, I used an end slash. Or remove the end slash.

    />
    OR
    </asp:whatever>

    Not both.

    Code:
    <asp:HyperLink 
    id="Hyperlink1"
    runat="server" 
    NavigateUrl="javascript:OpenPopup('largerImage.aspx?name="+<%# DataBinder.Eval(Container.DataItem, "Name")%>+"');"
    ImageUrl="../images/" + <%# DataBinder.Eval(Container.DataItem, "ImagePath") %>
    />
    OR
    Code:
    <asp:HyperLink 
    id="Hyperlink1"
    runat="server" 
    NavigateUrl="javascript:OpenPopup('largerImage.aspx?name="+<%# DataBinder.Eval(Container.DataItem, "Name")%>+"');"
    ImageUrl="../images/" + <%# DataBinder.Eval(Container.DataItem, "ImagePath") %>
    ></asp:HyperLink>
    You want that last semi-colon, it's for the javascript, not the asp code.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    New Coder
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi nikkiH,

    I'm sorry but I'm still getting the same error. I'm using Visual Studio Version 1.1. Do you think that this has anything to do with the problems with qoutes? I've tried putting single quotes around the tags but still same error.

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    You can always fall back to a normal anchor. That's all a hyperlink really is, unless you needed to script it at runtime.

    I think I got peeved too, because this is from my project LOL
    Code:
                     <ItemTemplate>
                        <a href='ReportListing.aspx?OfficeCode=<%# DataBinder.Eval(Container.DataItem, "OFFICE_CODE") %>'><%# DataBinder.Eval(Container.DataItem, "OFFICE_CODE") %></a>
                        </ItemTemplate>
    Another, with a script call.
    Code:
                        <ItemTemplate>                        
                            <a href="#" 
                            onclick='openEditWin(<%# DataBinder.Eval(Container.DataItem, "REPORT_ID") %>); return false;'>[edit]</a>
                        </ItemTemplate>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    New Coder
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi nikkiH, thanks for your help. I guess I will have to resort to a normal href. I was trying to have my user simply click on the image and show them an enlarged version of the image. Iíve figured out a way to navigate to a new page with this method but not to a new window. Iíll keep trying. If it fails Iíll add a href below the image with the line ďclick here for a larger imageĒ.

  • #10
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    A normal href is really just a link control, to the asp page.

    Don't kill yourself over it, unless you just want to play just for grins or for your own satisfaction.
    You can give a link an id and a runat=server and it ends up rendered as a server control. (HtmlAnchor)

    For example, you can have this control:
    <a href="#" runat="server" ID="linkTest" />

    And in page_load, this is perfectly fine and works.
    linkTest.InnerText = "Page_Load fired ";

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •