473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to change LinkButton forecolor in mouse over event

in asp.net 2.0, i have a link buttonand want to change the forecolor in a
mouse over event. how can I do this?

--
mo*******@noemail.noemail
Apr 2 '07 #1
7 21805
To do this you would use JavaScript to change the color using CSS.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"moondaddy" <mo*******@noemail.noemailwrote in message
news:ex*************@TK2MSFTNGP05.phx.gbl...
in asp.net 2.0, i have a link buttonand want to change the forecolor in a
mouse over event. how can I do this?

--
mo*******@noemail.noemail

Apr 2 '07 #2
use css:

<style>
a:hover {color:red}
</style>
-- bruce (sqlwork.com)
moondaddy wrote:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a
mouse over event. how can I do this?
Apr 2 '07 #3
OK Thanks.

I tried this but the style doesnt seem to effect it:

<style>
..clsHomePgLinkBtnNormal {font-size: 11pt; color: aqua; font-family:
'Microsoft Sans Serif'; }

..clsHomePgLinkBtnMouseOver {font-size: 11pt; color: white; font-family:
'Microsoft Sans Serif'; }

</style>

<asp:LinkButton ID="LinkButton1" runat="server"

onmouseover="LinkBtnMouseOver(this)"

onmouseout="LinkBtnMouseOut(this)"
>LinkButton</asp:LinkButton>

I put a debugger in here and the code executes with no error, but doesnt
have any effect on the link button's forecolor.

any suggestions?
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
To do this you would use JavaScript to change the color using CSS.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"moondaddy" <mo*******@noemail.noemailwrote in message
news:ex*************@TK2MSFTNGP05.phx.gbl...
>in asp.net 2.0, i have a link buttonand want to change the forecolor in a
mouse over event. how can I do this?

--
mo*******@noemail.noemail


Apr 2 '07 #4
Best way is to emit javascript after querying the control for its post back
event. I do not have a sample, but a google search should reveal something.
You can fudge the JavaScript with the control name in source, but you will
blow up if you change the location of the control (like move to a control in
the page). If you query the control, it will always give you the current
control name, regardless of position.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************
Think outside the box!
*********************************************
"moondaddy" <mo*******@noemail.noemailwrote in message
news:ex*************@TK2MSFTNGP05.phx.gbl...
in asp.net 2.0, i have a link buttonand want to change the forecolor in a
mouse over event. how can I do this?

--
mo*******@noemail.noemail
Apr 3 '07 #5
Thanks.

I think I know what the problem is, but I don't know the solution. the
mouseover event is calling a function which sets the css class. but the
color property has no effect on the button. If I change the font size in
the css class I can see this take effect in the mouseover event. I also
tried setting the forecolor via jscript with no luck.

<asp:LinkButton ID="LinkButton1" runat="server"
onmouseover="LinkBtnMouseOver(this)"
onmouseout="LinkBtnMouseOut(this)"
>Home</asp:LinkButton>
I debugged it and this passes in a correct reference to the link button.
the function calls the css class like this:
<script language="JavaScript" fptype="dynamicanimation">
function LinkBtnMouseOver(e)
{
debugger;
e.className='clsHomePgLinkBtnMouseOver';
e.ForeColor="Aqua"
}
function LinkBtnMouseOut(e)
{
e.className='clsHomePgLinkBtnNormal';
e.ForeColor="White"
}

//-->
</script>

and here's the style in the page:
<style>
.clsHomePgLinkBtnNormal {font-size: 11pt; color: white; font-family:
'Microsoft Sans Serif'; }
.clsHomePgLinkBtnMouseOver {font-size: 11pt; color: aqua; font-family:
'Microsoft Sans Serif'; }
</style>

seems like it should work but the for color does not change.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
Best way is to emit javascript after querying the control for its post
back event. I do not have a sample, but a google search should reveal
something. You can fudge the JavaScript with the control name in source,
but you will blow up if you change the location of the control (like move
to a control in the page). If you query the control, it will always give
you the current control name, regardless of position.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************
Think outside the box!
*********************************************
"moondaddy" <mo*******@noemail.noemailwrote in message
news:ex*************@TK2MSFTNGP05.phx.gbl...
>in asp.net 2.0, i have a link buttonand want to change the forecolor in a
mouse over event. how can I do this?

--
mo*******@noemail.noemail

Apr 3 '07 #6
OK I got it:

I need to change the element's style in javascript like this:
function LinkBtnMouseOver(e)
{
e.style.color="aqua";
}
function LinkBtnMouseOut(e)
{
e.style.color="white";
}


"moondaddy" <mo*******@noemail.noemailwrote in message
news:Or**************@TK2MSFTNGP05.phx.gbl...
Thanks.

I think I know what the problem is, but I don't know the solution. the
mouseover event is calling a function which sets the css class. but the
color property has no effect on the button. If I change the font size in
the css class I can see this take effect in the mouseover event. I also
tried setting the forecolor via jscript with no luck.

<asp:LinkButton ID="LinkButton1" runat="server"
onmouseover="LinkBtnMouseOver(this)"
onmouseout="LinkBtnMouseOut(this)"
Home</asp:LinkButton>

I debugged it and this passes in a correct reference to the link button.
the function calls the css class like this:
<script language="JavaScript" fptype="dynamicanimation">
function LinkBtnMouseOver(e)
{
debugger;
e.className='clsHomePgLinkBtnMouseOver';
e.ForeColor="Aqua"
}
function LinkBtnMouseOut(e)
{
e.className='clsHomePgLinkBtnNormal';
e.ForeColor="White"
}

//-->
</script>

and here's the style in the page:
<style>
.clsHomePgLinkBtnNormal {font-size: 11pt; color: white; font-family:
'Microsoft Sans Serif'; }
.clsHomePgLinkBtnMouseOver {font-size: 11pt; color: aqua; font-family:
'Microsoft Sans Serif'; }
</style>

seems like it should work but the for color does not change.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
>Best way is to emit javascript after querying the control for its post
back event. I do not have a sample, but a google search should reveal
something. You can fudge the JavaScript with the control name in source,
but you will blow up if you change the location of the control (like move
to a control in the page). If you query the control, it will always give
you the current control name, regardless of position.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************
Think outside the box!
*********************************************
"moondaddy" <mo*******@noemail.noemailwrote in message
news:ex*************@TK2MSFTNGP05.phx.gbl...
>>in asp.net 2.0, i have a link buttonand want to change the forecolor in
a mouse over event. how can I do this?

--
mo*******@noemail.noemail


Apr 3 '07 #7
The problem is you are not setting the right properties (you are trying to
set properties of a server control, but you should be setting properties of
the generated HTML element). try the following:

function LinkBtnMouseOver(e)
{
e.className='clsHomePgLinkBtnMouseOver';
e.style.color='Aqua';
}

You may also find the following site useful:

http://codepunk.hardwar.org.uk/css2js.htm

Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"moondaddy" <mo*******@noemail.noemailwrote in message
news:Or**************@TK2MSFTNGP05.phx.gbl...
Thanks.

I think I know what the problem is, but I don't know the solution. the
mouseover event is calling a function which sets the css class. but the
color property has no effect on the button. If I change the font size in
the css class I can see this take effect in the mouseover event. I also
tried setting the forecolor via jscript with no luck.

<asp:LinkButton ID="LinkButton1" runat="server"
onmouseover="LinkBtnMouseOver(this)"
onmouseout="LinkBtnMouseOut(this)"
Home</asp:LinkButton>

I debugged it and this passes in a correct reference to the link button.
the function calls the css class like this:
<script language="JavaScript" fptype="dynamicanimation">
function LinkBtnMouseOver(e)
{
debugger;
e.className='clsHomePgLinkBtnMouseOver';
e.ForeColor="Aqua"
}
function LinkBtnMouseOut(e)
{
e.className='clsHomePgLinkBtnNormal';
e.ForeColor="White"
}

//-->
</script>

and here's the style in the page:
<style>
.clsHomePgLinkBtnNormal {font-size: 11pt; color: white; font-family:
'Microsoft Sans Serif'; }
.clsHomePgLinkBtnMouseOver {font-size: 11pt; color: aqua; font-family:
'Microsoft Sans Serif'; }
</style>

seems like it should work but the for color does not change.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
>Best way is to emit javascript after querying the control for its post
back event. I do not have a sample, but a google search should reveal
something. You can fudge the JavaScript with the control name in source,
but you will blow up if you change the location of the control (like move
to a control in the page). If you query the control, it will always give
you the current control name, regardless of position.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*********************************************
Think outside the box!
*********************************************
"moondaddy" <mo*******@noemail.noemailwrote in message
news:ex*************@TK2MSFTNGP05.phx.gbl...
>>in asp.net 2.0, i have a link buttonand want to change the forecolor in
a mouse over event. how can I do this?

--
mo*******@noemail.noemail


Apr 3 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tshad | last post by:
I have a page where I want to set my linkbutton text using a class and cannot seem to get it to work using CSSClass, but it works fine using "ForeColor". Why is that? Here is the code:...
6
by: domtam | last post by:
First of all, my ASP.NET application has to support browser with Javascript disabled. In the application There is a control that looks like a text hyperlink, but the server-side has to do...
6
by: Shivakumar | last post by:
Hi all, Recently i have updated my vs.net 2003 project to vs.net 2005 and i have successfully converted my code and found no problem with all my controls except the one which is the linkbutton. ...
3
by: Steve Long | last post by:
I hope this isn't too stupid of a question but I'm looking for a way to change an item in a listview control when the mouse moves over it. I'd like to change its color and underline it for a...
3
by: settyv | last post by:
Hi, I need to generate PDF stream when i click on Linkbutton in datagrid ..At present i hardcoded the DMS Id and now it is working.But i need to pass DMS ID when click linkbutton.How can i do...
8
by: ontherun | last post by:
Hi All, I want to include some code for the OnTimer event in my Form "frmDueDateList" But when i open the form in the design view and checked the properties menu, i could not find the OnTimer...
5
daJunkCollector
by: daJunkCollector | last post by:
What I am doing here should be obvious. I have a datagrid that displays data properly. I want to create a linkbutton within each row of the datagrid that toggles a label control in the same row...
0
by: khanh | last post by:
I know how to highlight a treenode when the mouse is moving over it in a drag and drop, but what I would like to do is change the forecolor of a node and change it back when the mouse is moved away...
0
by: jeenajos | last post by:
Hi all, I dono wat happen to my code. It was working quite fine. But now link button click event is not firing. This linkbutton was used for navigation; first,next,previous,last. Can anyone...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.