Search code examples
asp.netframes

Call a code behind function from div/tables in aspx


Currently I am using frames in my webpage and I am calling a code behind function using src attribute. Now I wanted to remove frames from my webpage. Can I achieve the same behavior of method call when I replace frames with DIV or Table?

<FRAME name="nav" marginWidth="0" marginHeight="0" src="<%=fnGetMenuSource()%>" frameBorder="0" 
                noResize scrolling="no">

Solution

  • Sure, you can. With div, you can do like this:

    <div id="divNav" name="nav"><%=fnGetMenuSource()%></div>
    

    And in the code you might write the fnGetMenuSource() like this:

    protected string fnGetMenuSource()
    {
        return "<p style=\"color:red\">Hello World!</p>";
        // Or whatever you need
    }
    

    And the output for the code above:

    enter image description here