Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code was like this..But there was a problem..

The Controls collection cannot be modified because the control contains code blocks <%..%>
so, i had to chnage it..i got some solution telling to use [<%#](generally used for data binding) in place of <%=
but there is another proble arise..
we can't use <%#strbackPannel_Url %> or <%#classMenuobj.Menu_Name%> like previuosly i used it using <%= %> tag

so, how to call these things now???

C#
<ul class="nav nav-pills nav-stacked custom-nav">
                       <li><a href="<%=strbackPannel_Url %>Dashboard">class="fa fa-bullhorn" href="#"> <span><%= classMenuobj.Menu_Name%></span></a>
             <ul class="sub-menu-list">
                 <% foreach(dataGet_ModuleMenu classSubMenuObj in listSubMenu)
                    { %>
                 <li><a href="<%=classSubMenuObj.Menu_Link%>"> <%=classSubMenuObj.Menu_Name%></a></li>
                 <%} %>
             </ul>
         </li>
           <%}
             else
               { %>
               <li><a href="<%=classMenuobj.Menu_Link%>">^__i class="fa fa-bullhorn"> <span><%=classMenuobj.Menu_Name%></span></a></li>

              <%}
          } %>

                 </ul>
Posted
Updated 25-Oct-14 10:51am
v2
Comments
jkirkerx 25-Oct-14 16:53pm    
Have you considered just writing a user control?
Write a user control or server control in code behind to build your html, then just register the user control or server control.
/\jmot 25-Oct-14 16:56pm    
like what??will you please explain??
repeater??

1 solution

Watch this video on user controls

https://www.youtube.com/watch?v=iLDx8G8Qgb0[^]

What your doing in your example is old school, sort of asp classic or php like.
In asp.net, you can create a server control in code behind of html elements, or a user control, and just register the control using the <% %> and place the control in your desired location.

This is just a fast cut and paste example of how it works in VB, you can code in C# if you like, this example will not run. But the server control code is the basic format to start with, or you can go to solution explorer and load a template.

You build you control first, just the basics, a container with a border so you can see it first.
So you have a webform, you register the control and place the code in a container
and run the form to make sure you can see the control.
Then you start building out your control.

In the RenderDesignMode, you can build a preview of your control for use in the Visual Studio Design View. Keep in mind that in the RenderDesign, All your doing is creating something that represents the concept of the control, and allow you to edit the properties of the control using F4

The OnInit is for creating HTML Elements that persist on postback to the server
The OnLoad is for populate the elements, you can create HTML there to as well, but they won't persist on postback, you have to create them every time the page loads.


<![CDATA[<%@ Page Language="VB" MasterPageFile="~/masterpages/HomePage.master" ...
<%@ Register Assembly="redCopper.FlashObject_Net40" Namespace="FlashObject" TagPrefix="movie" %>]]>

<body>
<asp:content id="UpperContent" runat="Server" contentplaceholderid="UpperContent" mode="hold" xmlns:asp="#unknown" />    <div style="text-align: center; width: 960px; margin: 0px auto;">
        <div style="width: 758px; height: 400px;">
            <movie:flash_swfObject_2
                ID="T758x400"
                runat="server"
                Alignment="Center"
                AllowScriptAccess="samedomain"
                Flash_AutoPlay="True"
                Flash_BGColor="rgb(0,0,0)"
                Flash_ExpressInstall_Url="~/Flash/expressInstall.swf"
                Flash_MovieID="T758x400"
                Flash_MovieUrl="~/Flash/Jazz_Loader.swf"
                Flash_MovieUrl_Alt="~/Flash/Jazz_Loader.swf"
                Flash_Quality="AutoHigh"
                Flash_wMode="Transparent"
                Flash_ZIndex="900"
                Flash_LoopMovie="true"
                Style="top: 0px; left: -1px"
                Height="400px"
                Width="758px"
                DisplayAdvertisingFilmstrip_Specified="True"
                DisplayAdvertisingFilmstrip_Url="~/Flash/Jazz_Collection_NonFlash.html" />
        
</body>

And then you build your control
<DefaultProperty("Text"), ToolboxData("<{0}:FlashObject runat=server></{0}:FlashObject>")> _
Public Class flash_html_Object
    Inherits WebControl

    Private div_SWF_Container As Panel
    Private hl_TrialLink As HyperLink

    Public lit_AC_RunActiveContent As LiteralControl
    Public lit_FlashObject As LiteralControl
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

        If Not HttpContext.Current Is Nothing Then
            RenderContents(writer)
        Else
            RenderDesignMode(writer)
            RenderContents(writer)
        End If

End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
     MyBase.OnInit(e)

    Controls.Clear()  
    Dim panel_SWF_Container As Panel
    panel_SWF_Container = New Panel
    With panel_SWF_Container
        .ID = [ID] & "_panel_SWF_Container"
        .Style.Add(HtmlTextWriterStyle.Width, [Width].Value.ToString & "px")
        .Style.Add(HtmlTextWriterStyle.ZIndex, [Flash_ZIndex])
        .Style.Add(HtmlTextWriterStyle.Position, "relative")
        .Style.Add(HtmlTextWriterStyle.TextAlign, e_Movie_Alignment)
        .Style.Add(HtmlTextWriterStyle.Margin, "0px auto")
        .Style.Add(HtmlTextWriterStyle.Display, "Block")
    End With
    Controls.Add(panel_SWF_Container)

    div_SWF_Container = New Panel
    With div_SWF_Container
        .Style.Add(HtmlTextWriterStyle.Height, [Height].ToString)
        .Style.Add(HtmlTextWriterStyle.Width, [Width].ToString)
        .Style.Add(HtmlTextWriterStyle.TextAlign, e_Movie_Alignment)
    End With
    panel_SWF_Container.Controls.Add(div_SWF_Container)


End Sub
Private Sub RenderDesignMode(ByVal writer As HtmlTextWriter)

        Controls.Clear()
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)

    If Not Page.IsPostBack Then

    End If

End Sub
<Bindable(True)> _
<Category("Appearance")> _
<DefaultValue("(none)")> _
<Localizable(True)> _
Public Property Text() As String
    Get
        Dim _Text As String = CStr(ViewState("Text"))
        If _Text Is Nothing Then
            Return String.Empty
        Else
            Return _Text
        End If
    End Get

    Set(ByVal Value As String)
        ViewState("Text") = Value
    End Set

End Property
 
Share this answer
 
Comments
/\jmot 27-Oct-14 13:04pm    
user control solve my problem..thak you for that.
you were saying userControl and i was thing about top use asp.net control and fill from the code behing(i m so dumbo.. :P )
jkirkerx 27-Oct-14 13:07pm    
How about marking that as solved so others know what to do
You picked that up pretty quick.
That's one of the neat things about asp.net, gives you quite a bit of flexibility in designing and maintaining your forms.
/\jmot 27-Oct-14 13:08pm    
but have a question on it..
"What your doing in your example is old school, sort of asp classic or php like.
In asp.net, you can create a server control in code behind of html elements, or a user control, and just register the control using the <% %> and place the control in your desired location."

how to do this way, i need multiple html control..for menu and it's submenu,so, how can i bind that???
jkirkerx 27-Oct-14 13:39pm    
You make a skeleton master page of your HTML, and create containers for the reusable parts. Then you create user or server controls for the parts, and register the parts inside the containers.

Such parts would be the navigation menu, perhaps a product display system and so forth. Now the parts are reusable, you control just 1 source for the user control, and never have to update every form you use the part on. Just update it once in 1 place.
/\jmot 27-Oct-14 14:37pm    
ohhhkk...thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900