<%=和<%#tag的问题 [英] Problem with <%= and <%# tag

查看:62
本文介绍了<%=和<%#tag的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是这样的..但是有一个问题..



控件集合无法修改,因为控件包含代码块< %..%>

所以,我不得不对它进行处理..我得到一些解决方案告诉使用 [<%#](通常用于数据绑定)代替<%=

但是还有另外一个问题..

我们可以不要使用<%#strbackPannel_Url%>或<%#classMenuobj.Menu_Name%>就像previuosly我使用<%=%>标签


所以,现在如何调用这些东西???



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???

<ul class="nav nav-pills nav-stacked custom-nav">
                       <li><a href="<%=strbackPannel_Url %>Dashboard">class="fa fa-bullhorn"> <span>Dasboard</span></a></li>

                     <% List<dataGet_ModuleMenu> listMenu= classMenu.ActionGet_Module_Menu(); %>
                      <%foreach (dataGet_ModuleMenu classMenuobj in listMenu)
         {
            List<dataGet_ModuleMenu> listSubMenu= classMenu.ActionGet_SubMenu(classMenuobj.Menu_Id);
                 if (listSubMenu.Count> 0)
            {  %>
                     <li class="menu-list"><a href="#">class="fa fa-home"> <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%>">class="fa fa-bullhorn"> <span><%=classMenuobj.Menu_Name%></span></a></li>

              <%}
          } %>

                 </ul>

推荐答案

观看此视频用户控制



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



你在你的例子中所做的是老式学校,有点像asp经典或者像php一样。

在asp.net中,你可以创建html元素或用户控件后面的代码中的服务器控件,只需使用< %%>注册控件即可。将控件放在你想要的位置。



这只是一个快速剪切和粘贴的例子,说明它在VB中是如何工作的,你可以用C#编写代码,如果你愿意的话,这个例子不会运行。但是服务器控制代码是开始时的基本格式,或者你可以去解决方案资源管理器并加载模板。



你首先构建你的控件,只是基础知识,一个带边框的容器,所以你可以先看到它。

所以你有一个webform,你注册控件并将代码放在一个容器中

并运行表单确保你可以看到控件。

然后你开始构建你的控件。



在RenderDesignMode中,你可以构建一个控件的预览版,以便在Visual Studio中使用设计视图。请记住,在RenderDesign中,您所做的一切都是创建代表控件概念的东西,并允许您使用F4编辑控件的属性



OnInit用于创建在回发到服务器时保留的HTML元素

OnLoad用于填充元素,您也可以在那里创建HTML,但它们不会在回发时保留,你有每次加载页面时都要创建它们。





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


这篇关于&lt;%=和&lt;%#tag的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆