By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,133 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,133 IT Pros & Developers. It's quick & easy.

Setting button color not being rendered

P: n/a
I want to be able to change the color of the text of a button after it is
pressed.

The first part of the event is:

sub submitQuestion_click(Sender as Object, e as EventArgs)
trace.warn("Sender text = " & Sender.text)
trace.warn("Sender color = " & Sender.ForeColor.ToString())
Sender.ForeColor = System.Drawing.Color.Red

I am doing the trace.warns to make sure I have the correct button. And to
make sure the color was changed ( and is being preserved as the page is
posted back) - which it is.

The trace shows:

Sender text = Select 0.004294 0.000098
Sender color = Color [Red] 0.004396 0.000102

(it shows Color [Empty] the first time through as it should).

But the buttons text does not show as read. From viewsource it shows as:

<input type="submit" name="DataList1:_ctl3:submitQuestion" value="Select"
id="DataList1__ctl3_submitQuestion" />

As you can see, there is no red being rendered?

How do I do this?

Thanks,

Tom
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
I want to be able to change the color of the text of a button after it is
pressed.

The first part of the event is:

sub submitQuestion_click(Sender as Object, e as EventArgs)
trace.warn("Sender text = " & Sender.text)
trace.warn("Sender color = " & Sender.ForeColor.ToString())
Sender.ForeColor = System.Drawing.Color.Red

I am doing the trace.warns to make sure I have the correct button. And to
make sure the color was changed ( and is being preserved as the page is
posted back) - which it is.

The trace shows:

Sender text = Select 0.004294 0.000098
Sender color = Color [Red] 0.004396 0.000102

(it shows Color [Empty] the first time through as it should).

But the buttons text does not show as read. From viewsource it shows as:

<input type="submit" name="DataList1:_ctl3:submitQuestion" value="Select"
id="DataList1__ctl3_submitQuestion" />

As you can see, there is no red being rendered?

How do I do this?
MS docs say that Forecolor is supposed to set the text color of the button

I also tried:

Dim submitButton as Button = CType(sender,button)
submitButton.Style = "color:red"

But get an error that "style" is read only.

For a test, I tried to set "forecolor=red" on the object itself:

<asp:button ID="submitQuestion" ForeColor="red" CommandName="SubmitQuestion"
runat="server" Text="Select" OnClick="submitQuestion_click" />

And it never renders the red.

If I put the style on the object:

<asp:button ID="submitQuestion" style="color:red"
CommandName="SubmitQuestion" runat="server" Text="Select"
OnClick="submitQuestion_click" />

It renders fine and the color of the text is shown correctly.

In one case, it doesn't work at all (even though MS says it will), in the
other case (which works initially) - you can't change it.

How do I get around this?

Tom
Thanks,

Tom

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.