c# - Change button style on page load -
this table , on table have cells in form of buttons. css sheet have made them green.
<asp:table id="table1" runat="server" borderwidth="2px" bordercolor="#0033cc" backcolor="#ffcccc" > <asp:tablerow> <asp:tablecell cssclass="table-cell-room" id="d256">d256<br /></asp:tablecell> <asp:tablecell><asp:button runat="server" width="100px" text="boka" id="r1b1" onclick="button_click_first_row" cssclass="buttons"/></asp:tablecell> <asp:tablecell><asp:button runat="server" width="100px" text="boka" id="r1b2" onclick="button_click_first_row" cssclass="buttons"/></asp:tablecell> <asp:tablecell><asp:button runat="server" width="100px" text="boka" id="r1b3" onclick="button_click_first_row" cssclass="buttons"/></asp:tablecell> <asp:tablecell><asp:button runat="server" width="100px" text="boka" id="r1b4" onclick="button_click_first_row" cssclass="buttons"/></asp:tablecell> <asp:tablecell><asp:button runat="server" width="100px" text="boka" id="r1b5" onclick="button_click_first_row" cssclass="buttons"/></asp:tablecell> </asp:tablerow>
i have database table called room
, contains id, button_id , checkifbooked. want utilize "colum" checkedifbook see if booked, meaning checkedifbooked = 1.
all of work have no thought style buttons on table of have checkedifbooked = 1.
meaning in database table have r1b1 , it's value checkedifbooked = 1. have no thought code in page load. don't want utilize
if(button_id == r1b2){ checkedifbooked == 1 //do styling on button }
cause have alot of buttons , in c# code utilize sender new button right id button clicked.
possible solution #1
when rendering page, add together additional css class button if isbooked = true
if (isbooked) { /// render "isbooked" tablecell button <asp:tablecell> ... cssclass="isbooked"/></asp:tablecell> } else { /// render "not booked" tablecell button <asp:tablecell> ... cssclass="button"/></asp:tablecell> }
then in css:
.isbooked { /* isbooked button styles here */ }
so when code gets rendered html, css classes in place:
<!-- illustration html output --> < ... class="button" ... ></> < ... class="isbooked" ... ></> < ... class="button" ... ></>
possible solution #2 on page load, have jquery booked buttons, , disable them, or style them, etc..
$(document).ready(function(){ $("isbooked").each(function(index){ // each isbooked element available via $(this) $(this).addclass("bookedbutton"); $(this).prop("disabled", true); // ... }); });
security note: disabling form button on client-side (via javascript) isn't enough, need validate info on server side. if disable form elements on client, create sure server verifies nil "booked" trying submitted form.
hope helps.
c# database button styles
No comments:
Post a Comment