Setting button color not being rendered

T

tshad

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
 
T

tshad

tshad said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top