Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. help in ItemCreated method plus javascript

help in ItemCreated method plus javascript

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netdatabasehelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sujay chakraborty
    wrote on last edited by
    #1

    Hi all, I am working on a ASP.NET project where i am displaying several images and their details, both coming from a database table. What i want is i am calling a javascript when some one moves the mouse cursor over the image, for that i have designed the javascript but the javascript depends on the id (stored as a coloumn in the same table) of the row containing the image on which the cursor is positioned. I have taken the id field in an hidden field and tried the following code

    protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
    {
    ListItemType elemType = e.Item.ItemType;
    if ((elemType == ListItemType.Item) || (elemType == ListItemType.AlternatingItem))
    {
    CheckBox cBox = (CheckBox)e.Item.FindControl("chkSel");
    Image pimg = (Image)e.Item.FindControl("Image2");
    HiddenField hf_Pid = (HiddenField)e.Item.FindControl("hfPid");
    pimg.Attributes.Add("onmouseover", "showButton('"+hf_Pid.Value+"');");
    cBox.CheckedChanged += new EventHandler(OnChangeHandler);
    }
    }

    The idea is to find the value in the hidden field that is coming from the database and then pass it to the showButton() function in the javascript. But this doesn't seemed to work. Please help me in accomplishing this task. Your help will be highly appreciated. Thanks in advance Regards Sujay

    S B 2 Replies Last reply
    0
    • S Sujay chakraborty

      Hi all, I am working on a ASP.NET project where i am displaying several images and their details, both coming from a database table. What i want is i am calling a javascript when some one moves the mouse cursor over the image, for that i have designed the javascript but the javascript depends on the id (stored as a coloumn in the same table) of the row containing the image on which the cursor is positioned. I have taken the id field in an hidden field and tried the following code

      protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
      {
      ListItemType elemType = e.Item.ItemType;
      if ((elemType == ListItemType.Item) || (elemType == ListItemType.AlternatingItem))
      {
      CheckBox cBox = (CheckBox)e.Item.FindControl("chkSel");
      Image pimg = (Image)e.Item.FindControl("Image2");
      HiddenField hf_Pid = (HiddenField)e.Item.FindControl("hfPid");
      pimg.Attributes.Add("onmouseover", "showButton('"+hf_Pid.Value+"');");
      cBox.CheckedChanged += new EventHandler(OnChangeHandler);
      }
      }

      The idea is to find the value in the hidden field that is coming from the database and then pass it to the showButton() function in the javascript. But this doesn't seemed to work. Please help me in accomplishing this task. Your help will be highly appreciated. Thanks in advance Regards Sujay

      S Offline
      S Offline
      Sujay chakraborty
      wrote on last edited by
      #2

      hello all, well please help in solving this issue......... plzzzzz. its really urgent..... Waiting for a reply Regards Sujay

      1 Reply Last reply
      0
      • S Sujay chakraborty

        Hi all, I am working on a ASP.NET project where i am displaying several images and their details, both coming from a database table. What i want is i am calling a javascript when some one moves the mouse cursor over the image, for that i have designed the javascript but the javascript depends on the id (stored as a coloumn in the same table) of the row containing the image on which the cursor is positioned. I have taken the id field in an hidden field and tried the following code

        protected void DataList1_ItemCreated(object sender, DataListItemEventArgs e)
        {
        ListItemType elemType = e.Item.ItemType;
        if ((elemType == ListItemType.Item) || (elemType == ListItemType.AlternatingItem))
        {
        CheckBox cBox = (CheckBox)e.Item.FindControl("chkSel");
        Image pimg = (Image)e.Item.FindControl("Image2");
        HiddenField hf_Pid = (HiddenField)e.Item.FindControl("hfPid");
        pimg.Attributes.Add("onmouseover", "showButton('"+hf_Pid.Value+"');");
        cBox.CheckedChanged += new EventHandler(OnChangeHandler);
        }
        }

        The idea is to find the value in the hidden field that is coming from the database and then pass it to the showButton() function in the javascript. But this doesn't seemed to work. Please help me in accomplishing this task. Your help will be highly appreciated. Thanks in advance Regards Sujay

        B Offline
        B Offline
        Brian W King
        wrote on last edited by
        #3

        hhmmm. I have done the same thing and found an issue with making it work. I cannot update dynamically via javascript, any asp.net control on a page that was not created by code behind. If the control is cast on the aspx page, I cannot touch it by referencing the name dynamically in javascript (odd, but repeatable behaviour). If I create the control via code behind instead, the exact same routine in javascript will work. Note, the method that does not work, will not throw errors either. It just ignores your code (so it seems). Try creating the checkbox in the onload routine instead and see if it works that way (give the table or container the checkbox exists in an ID so you can add the checkbox with code behind instead). You are on the right track, absolutely. I think its the weird behaviour that is hanging you.

        L 1 Reply Last reply
        0
        • B Brian W King

          hhmmm. I have done the same thing and found an issue with making it work. I cannot update dynamically via javascript, any asp.net control on a page that was not created by code behind. If the control is cast on the aspx page, I cannot touch it by referencing the name dynamically in javascript (odd, but repeatable behaviour). If I create the control via code behind instead, the exact same routine in javascript will work. Note, the method that does not work, will not throw errors either. It just ignores your code (so it seems). Try creating the checkbox in the onload routine instead and see if it works that way (give the table or container the checkbox exists in an ID so you can add the checkbox with code behind instead). You are on the right track, absolutely. I think its the weird behaviour that is hanging you.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Which thing is not working properly? Tell whether the onmouseover event is not working. Or The onmouseover is working but the id in the hidden field is empty. if so, then you can get the value of the hidden field in ItemDataBound event only.

          B S 2 Replies Last reply
          0
          • L Lost User

            Which thing is not working properly? Tell whether the onmouseover event is not working. Or The onmouseover is working but the id in the hidden field is empty. if so, then you can get the value of the hidden field in ItemDataBound event only.

            B Offline
            B Offline
            Brian W King
            wrote on last edited by
            #5

            I realize in reviewing this that there are several more caveats to it that cause this issue. I think I will cut bait here and run. Sorry.

            1 Reply Last reply
            0
            • L Lost User

              Which thing is not working properly? Tell whether the onmouseover event is not working. Or The onmouseover is working but the id in the hidden field is empty. if so, then you can get the value of the hidden field in ItemDataBound event only.

              S Offline
              S Offline
              Sujay chakraborty
              wrote on last edited by
              #6

              Thank you Ramesh, Actually the problem is that the hidden field value that i am trying to pass to the javascript is always showing null, but the hidden field is having the value when viewed from the source of the page from browser. I wonder if the ItemDataBound event will allow me to add the javascript to the imgage tag. Regards Sujay

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups