Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by eghtebas
at 2024-07-26 11:57:23
Point:500 Replies:8 POST_ID:829121USER_ID:11934
Topic:
C# Programming Language;.NET;Cascading Style Sheets (CSS)
In the event below, (sender as Button).ID gives the btn1, btn2, etc. that is pressed.
Question: How can I change the background color (change css file) of the pressed button?
The default CSS of the buttons are also included below. Please suggest a nice looking pressed style if you know one.
Thank you
Question: How can I change the background color (change css file) of the pressed button?
The default CSS of the buttons are also included below. Please suggest a nice looking pressed style if you know one.
Thank you
protected void btn1_Click(object sender, EventArgs e) { string strNo=""; switch ((sender as Button).ID) { case "btn1": strNo = "f123"; break; case "btn2": strNo = "f123"; break; case "btn3": strNo = "f123"; break; case "btn4": strNo = "f456"; break; case "btn5": strNo = "f456"; break; case "btn6": strNo = "f456"; break; case "btn7": strNo = "f7"; break; case "btn8": strNo = "f8"; break; case "btn9": strNo = "f9"; break; case "btn10": strNo = "f10"; break; case "btn11": strNo = "f11"; break; case "btn12": strNo = "f12"; break; } Response.Write(strNo); lblCmdOpt.Text = strNo; Session["strNo"] = strNo; // Response.Redirect("Default2.aspx"); }css:#btn1, #btn2, #btn3, #btn4, #btn5, #btn6, #btn7, #btn8, #btn9, #btn10, #btn11, #btn12 { background: #297cb3; background-image: -webkit-linear-gradient(top, #297cb3, #47a1d9); background-image: -moz-linear-gradient(top, #297cb3, #47a1d9); background-image: -ms-linear-gradient(top, #297cb3, #47a1d9); background-image: -o-linear-gradient(top, #297cb3, #47a1d9); background-image: linear-gradient(to bottom, #297cb3, #47a1d9); -webkit-border-radius: 6; -moz-border-radius: 6; border-radius: 6px; -webkit-box-shadow: 1px 2px 4px #797999; -moz-box-shadow: 1px 2px 4px #797999; box-shadow: 1px 2px 4px #797999; font-family: Arial; color: #ffffff; font-size: 16px; padding: 7px; border: solid #1f628d 0px; text-decoration: none;} 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:
Attachment:PressedButton.png
Expert: duncanb7 replied at 2024-07-29 09:48:16
I think I misunderstand your question in previous post, you are talking about
the CSS button or CSS output on the ajax website and you are NOT wanting to use Ajax to get session data,
Right ?
For the CSS priority, you can read this article about style Precedence CSS, http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/
1-inline-style such as on tag style, for example, <a style="color:....>
2- css id
3- css class
4- css tag element
Duncan
the CSS button or CSS output on the ajax website and you are NOT wanting to use Ajax to get session data,
Right ?
For the CSS priority, you can read this article about style Precedence CSS, http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/
1-inline-style such as on tag style, for example, <a style="color:....>
2- css id
3- css class
4- css tag element
Duncan
Author: eghtebas replied at 2024-07-29 09:04:07
See the link for the question:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28486190.html
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_28486190.html
Author: eghtebas replied at 2024-07-29 08:58:25
Hi Duncan,
I used:
I used:
int i; for (i = 1; i < 11; i++) { Button btn = (Button)this.FindControl("btn" + i.ToString()); btn.BackColor = btn12.BackColor; } if (Session["pressedButton"] != null) { string strButton = Session["pressedButton"].ToString(); Button btn = (Button)this.FindControl(strButton); btn.BackColor = Color.Orange; var c = btn12.BackColor; c = btn.BackColor; } 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:
Note that btn12 has no settings (its blank and gets its style from a css file). So instead of:
btn.BackColor = ""; or btn.BackColor = null; I used btn.BackColor = btn12.BackColor;
At line 14 (var c = btn12.BackColor;) no settings for btn12 reads c="{Name=0, ARGB(0,0,0,0)}", and
At line 15 (c = btn.BackColor;) the settings for the current btn reads c="{Name=Orange, ARGB(255,255,165,0)}",
Question: Can I then replace line 5 (btn.BackColor = btn12.BackColor;) with:
btn.BackColor = "{Name=0, ARGB(0,0,0,0)}";
Because neither of btn.BackColor = ""; or btn.BackColor = null; work.
Mike
Expert: duncanb7 replied at 2024-07-29 08:24:33
Thanks for your points
And it sounds correct You get session data from other sites page , right ?
Be reminded, ajax is only allowed for the same domain communication within both pages must
be at http://yourdomain for todays' browser since browser vendor change its policy .
Duncan
And it sounds correct You get session data from other sites page , right ?
Be reminded, ajax is only allowed for the same domain communication within both pages must
be at http://yourdomain for todays' browser since browser vendor change its policy .
Duncan
Author: eghtebas replied at 2024-07-27 13:07:41
Hi Duncan,
I have revised the code and all session variable works fine. The problem is that ultimately this is css determines what color is used.
Here is the cs code followed by the css for buttons.
I have revised the code and all session variable works fine. The problem is that ultimately this is css determines what color is used.
Here is the cs code followed by the css for buttons.
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Drawing;public partial class MasterPage : System.Web.UI.MasterPage{ //Page myMaster = this as Page; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { lblCmdOpt.Text = "IsPostBack"; if (Session["strBtn"] != null) { string strBtn = (string)Session["strBtn"]; Button btn = (Button)this.FindControl(strBtn); btn.BackColor = Color.Red; } } else { lblCmdOpt.Text = (Session["strNo"]==null)? "is null":Session["strNo"].ToString(); } } protected void btn1_Click(object sender, EventArgs e) { string strNo=""; string strBtn=((sender as Button).ID).ToString(); switch (strBtn) { case "btn1": strNo = "f123"; break; case "btn2": strNo = "f123"; break; case "btn3": strNo = "f123"; break; case "btn4": strNo = "f456"; break; case "btn5": strNo = "f456"; break; case "btn6": strNo = "f456"; break; case "btn7": strNo = "f7"; break; case "btn8": strNo = "f8"; break; case "btn9": strNo = "f9"; break; case "btn10": strNo = "f10"; break; case "btn11": strNo = "f11"; break; case "btn12": strNo = "f12"; break; } Response.Write(strNo); lblCmdOpt.Text = strNo; Session["strBtn"] = strBtn; Response.Redirect("Default2.aspx",false); } }'..#btn1, #btn2, #btn3, #btn4, #btn5, #btn6, #btn7, #btn8, #btn9, #btn10, #btn11, #btn12 { background: blue;..} 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:
I think we need to have to have a second set of css for a class name .buttonPressed :
Now, the question really is how to add class="buttonPressed" to the pressed button identified by Session["strBtn"] variable in Page_Load event.
Question: Does this sound reasonable and the only solution?
Meanwhile I tested this and found out the when both ID and class are used in a css file, ID overwrites class. Meaning even if we could do the coding described above add a class to aspx file will not solve the problem.
Toggle Button example below may help with coming up with the solution: http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/ToggleButton/ToggleButton.aspx
I am reading through but I have not use ajax before.
Thank you,
Mike
Question: Does this sound reasonable and the only solution?
Meanwhile I tested this and found out the when both ID and class are used in a css file, ID overwrites class. Meaning even if we could do the coding described above add a class to aspx file will not solve the problem.
Toggle Button example below may help with coming up with the solution: http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/ToggleButton/ToggleButton.aspx
I am reading through but I have not use ajax before.
Thank you,
Mike
Accepted Solution
Expert: duncanb7 replied at 2024-07-27 12:39:40
500 points EXCELLENT
Dear Author,
If you provide more or complete code ( not security issue), it will assist on it
I don't know why I am only one to reply this thread. Could you click "Request Attention" to let other experts assist on it ?
Duncan
If you provide more or complete code ( not security issue), it will assist on it
I don't know why I am only one to reply this thread. Could you click "Request Attention" to let other experts assist on it ?
Duncan
Author: eghtebas replied at 2024-07-27 12:28:17
Hi Duncan,
Thank you for the response. I tried:
string strBtn=((sender as Button).ID).ToString();
Button btn = (Button)this.FindControl(strBtn);
btn.BackColor = Color.Red;
it doesn't work, I suppose I have to use a session variable to store the name of the button and use it to change that button's color in Page_Load event. As it is, I am not seeing the change of color.
Question: If this sounds reasonable, how do I store the button name in the session variable and reuse it later on?
Thank again,
Mike
Thank you for the response. I tried:
string strBtn=((sender as Button).ID).ToString();
Button btn = (Button)this.FindControl(strBtn);
btn.BackColor = Color.Red;
it doesn't work, I suppose I have to use a session variable to store the name of the button and use it to change that button's color in Page_Load event. As it is, I am not seeing the change of color.
Question: If this sounds reasonable, how do I store the button name in the session variable and reuse it later on?
Thank again,
Mike
Expert: duncanb7 replied at 2024-07-26 23:38:46
Is it what your want ?why don't change it on CSS ?
DUncan
DUncan
;