Table cells background

Discussion in 'ASP .Net' started by Guest, Mar 7, 2006.

  1. Guest

    Guest Guest

    Hi,
    Can anyone tell me how to change a table cells background color or
    background image in runtime with C#.

    Karl-Inge
     
    Guest, Mar 7, 2006
    #1
    1. Advertisements

  2. Guest

    Guest Guest

    You can use the cssClass attribute, e.g.

    ..TableCell1
    {
    background-image:url("images/Image1.gif");
    }

    and in your C# code:

    TableCell td1= new TableCell();
    td1.CssClass = "TableCell1";

    //or you can add it without a CssClass like this:
    td.Height = "100px";
    td1.Width = "100px";
    td1.Style.Add("background-image", "url('image1.gif')");
     
    Guest, Mar 7, 2006
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    Thanks Williams

    Karl-Inge

     
    Guest, Mar 8, 2006
    #3
  4. Guest

    Guest Guest

    Hi Phillips

    Your suggestion help me in the right directions, but I have still problem.
    I’m trying to make a tab style horizontal menu similar to that you use on top
    of your web http://www.webswapp.com.

    Do you have an example?

    Karl-Inge
     
    Guest, Mar 8, 2006
    #4
  5. Guest

    Guest Guest

    Hi Karl-Inge,

    In displaying menu items on my website, I use a Button server control whose
    cssClass is set with a background image that gives that impression of a Tab
    (without the rectangular edges). The button has both the onmouseout and
    onmouseover events changing the cssClass (which in turn displays a different
    background image to the button).
     
    Guest, Mar 8, 2006
    #5
  6. Guest

    Guest Guest

    Hi Phillip

    Thanks for your help.

    I can now change the buttons style with onmouseover and onmouseout.
    My next problem is how I can reach a CSharp script when click the button.


    Karl-Inge
     
    Guest, Mar 8, 2006
    #6
  7. Guest

    Guest Guest

    Hi,

    I found the solution. "onserverclick" trigger C# event

    Karl-Inge
     
    Guest, Mar 9, 2006
    #7
  8. Guest

    Guest Guest

    You must have used an HtmlInputButton <input type="button"> object. If you
    had used a Button server control it would have equally worked with the
    Button.Click event, e..g

    <asp:Button OnClick="ServerFunction"
    onmouseover="this.className='something';"
    onmouseout="this.className='somethingelse';" Text="Menu1"
    runat="sever"></asp:Button>
     
    Guest, Mar 10, 2006
    #8
  9. Guest

    Guest Guest

    Thank you Phillip

    Yes, I used HthmlInputButton with runat=server, and that work fin.

    Your suggestion work, but IntelliSense don’t give me the choose
    “onmouseover, onmouseout†and I cant find information in Visual studio 2005
    documentation that asp:button support this events?

    Is it some basic information I have missed?

    Karl-Inge Reknes
     
    Guest, Mar 10, 2006
    #9
  10. Guest

    Ray Booysen Guest

    Those events are javascript. You'll have to write the event code yourself.
     
    Ray Booysen, Mar 10, 2006
    #10
  11. Guest

    Guest Guest

    Hi Karl-Inge,

    No, it is not exactly basic information that you missed; rather it is
    programming knowledge that you would have acquired had you worked with DHTML
    before the ASP.NET server controls had come along. :)

    ASP.NET server controls are very excellent creatures in allowing programmers
    powerful interfaces without having to learn all of the details of the HTML
    objects that they render. The onmouseover and onmouseout attributes could
    have been done in a more elegant manner without having the intellisense
    complaining about them like this in the codebehind (e.g. during the Page
    PreRender event handling):

    Button1.Attributes.Add("onmouseover", "this.className='class1';")
    Button2.Attributes.Add("onmouseout", "this.className='class2';")
     
    Guest, Mar 11, 2006
    #11
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.