help in ItemCreated method plus javascript
-
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
-
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
hello all, well please help in solving this issue......... plzzzzz. its really urgent..... Waiting for a reply Regards Sujay
-
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
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.
-
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.
-
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.
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.
-
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.
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