I have a page that have a dinamic menu and i have created a function to create the correct HTML to view the menu, but how can I call this function in my aspx page that I see the generated HTML in the correct position?? :rolleyes:

Dani AI

Generated

Quick summary and practical options (building on 's user-control suggestion and ' goal of producing user-specific HTML at render time).

If the HTML is purely presentational (no server events inside the menu) the simplest approach is a server-side Literal or PlaceHolder placed where you want the menu, then set its Text during the page lifecycle (usually Page_Load). If the menu must contain server controls that raise events, create them (or load a UserControl) during Page_Init so viewstate and events work across postbacks.

Example (VB.NET):

<!-- in the .aspx where the menu should appear -->
<asp:Literal ID="litMenu" runat="server" />
' in code-behind
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        litMenu.Text = GenerateMenuForUser(User.Identity.Name)
    End If
End Sub

Private Function GenerateMenuForUser(userName As String) As String
    Dim sb As New System.Text.StringBuilder()
    sb.Append("<ul class=""menu"">")
    ' build items from DB, encoding any user-supplied text
    sb.Append("</ul>")
    Return sb.ToString()
End Function

If you prefer encapsulation, create a Menu.ascx that accepts a user or role property and render it in the page (either declaratively or with LoadControl). That keeps markup and logic together and is the pattern pointed at.

Notes and troubleshooting

  • Do not store raw HTML in the DB unless it is strictly sanitized; HtmlEncode user data before inserting labels to avoid XSS.
  • Cache menu HTML per user/role where appropriate to reduce DB hits.
  • If you add interactive server controls dynamically, create them in Page_Init with stable IDs so events fire.

About 's SQL function: the posted CREATE FUNCTION is not valid for doing updates. In SQL Server, use a stored procedure for DML (UPDATE/INSERT/DELETE) or make the function return a table (no side effects). From ASP.NET call a stored procedure with CommandType.StoredProcedure and ExecuteNonQuery, or call a table-valued function with a parameterized SELECT and read the results.

Thanks for your help but I want to generate dinamic HTML during compilation of the page.
When the user login in the application i generate the correct HTML with a check to the right that are stored in the database.
DIfferent user have differenz HTML page, i don't have any event and any botton, I must display different page to different users.
I have create a sub that create the correct HTML but I don't now how call this sub to print out the result.

I found in the tutorial that you have post it in an other page the solution to my problem thanks a lot for your help. :) :)

CREATE FUNCTION dbo.update
	(
    @Quantity int
    )
RETURNS TABLE
AS
GO
UPDATE Quantity.Quantity1
SET Quantity = Quantity+Quantity
FROM Quantity.Quantity1 AS sp
JOIN Quantity.InwardEntries AS so
ON sp.Id = so.Id 

GO





	RETURN /*select ... from ... */

how to call above function in asp.net

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.