none
How to assing an ID to an html element using writer.write functions....

    問題

  • I have a web part in SharePoint that reads a string with URL.

    I am trying to display those string in a tabular format using some css.

    I am using writer.Write functions to do all the work here..

    I am able to create HTML elements say a table and apply CSS to but  only inline process.

    I am trying to add  an id to the TABLE and write a CSS to that ID so the elements underneath can be addressed but somehow i am not able to achive it...

    Here is the codes

    to create CSS:

    string css = Environment.NewLine;
                        css += "<style type=\"text/css\">" + Environment.NewLine;
    
                        css += "#navigate {list-style: none;    padding: 0;    margin: 0;    white-space: nowrap;}" + Environment.NewLine;
       css += ".navigatem li{ float: left; background-color: #eee;   position: relative;  top: 1px;}" + Environment.NewLine;
    
     writer.Write("<table id=\"navigate\" >);"
    // or adding a class**************
    writer.Write("<table style=\" class=navigate \" >);"
    
    
    //Only Inline works 


    kukdai

    2012年6月21日 下午 07:05

所有回覆

  • kukdai,

    check out

    Use of the HtmlTextWriter Class to Render Custom Controls

    http://www.vbdotnetheaven.com/UploadFile/scottlysle/HtmTextWriterIntro11132006230833PM/HtmTextWriterIntro.aspx

    writer.RenderBeginTag(HtmlTextWriterTag.Table);

    writer.AddAttribute(HtmlTextWriterAttribute.Id,"navigate");



    Thanks
    Akhilesh Nirapure

    2012年6月22日 下午 07:34
  • thanks for the answer.

    Now i want to apply the CSS written above.

    i want to do it with id so that the child elements carryover the style effects.

    how can i apply the css from code behind.

    i declared a string named css as above and defined the classes that will be used through out the control..

    i am basically creating a following controls in order ----->UL--li---a---span

    so i want each element to have the styles as i specified in the string as above....

    how do i do that.....


    kukdai

    2012年7月2日 下午 07:36