【问题标题】:Asp Hyperlink's attribute cannot be changed using code behind无法使用后面的代码更改 Asp 超链接的属性
【发布时间】:2010-10-07 06:22:04
【问题描述】:

我是 asp.net 的新手。我正在尝试将文本和 URL 从数据库加载到超链接中。调试后发现值已经成功加载到超链接控件中,但是在html代码中没有显示?有谁知道这是怎么发生的?对不起我的英语不好。

                If myReader2.Read Then
                             Dim temp_panel As Panel
                            Dim temp_hyperlink As HyperLink                                
                            temp_panel = FindControlRecursive(Me, "Panel" & i.ToString())
                            temp_panel.CssClass = "accordionItem"                                
                            temp_hyperlink = FindControlRecursive(Me, "HyperLink" & (i).ToString())
                            temp_hyperlink.Text = myReader2("Text")
                            temp_hyperlink.NavigateUrl = myReader2("Link")
                            temp_hyperlink.CssClass = "accordionItem"
                            temp_hyperlink.RenderControl(o)
                            myConn2.Close()
                End If

上面是代码隐藏。

  <asp:Panel ID="Panel1" runat="server" class="accordionIteminvisible"><asp:HyperLink ID="HyperLink1" runat="server" /></asp:Panel>
                            <asp:Panel ID="Panel2" runat="server" class="accordionIteminvisible"><asp:HyperLink ID="HyperLink2" runat="server" /></asp:Panel>
                            <asp:Panel ID="Panel3" runat="server" class="accordionIteminvisible"><asp:HyperLink ID="HyperLink3" runat="server" /></asp:Panel>

上面是asp代码。

                            <div id="ctl00_AccordionPane1_content_Panel1" class="accordionIteminvisible"> 

    </div> 
                            <div id="ctl00_AccordionPane1_content_Panel2" class="accordionIteminvisible"> 
        <a id="ctl00_AccordionPane1_content_HyperLink2"></a> 
    </div> 
                            <div id="ctl00_AccordionPane1_content_Panel3" class="accordionIteminvisible"> 
        <a id="ctl00_AccordionPane1_content_HyperLink3"></a> 
    </div> 

上面是html代码。

【问题讨论】:

    标签: asp.net vb.net controls hyperlink render


    【解决方案1】:

    编辑:原始发帖人回答了他自己的问题,但将这个问题标记为答案。 OP的解决方案:

    问题是这个页面是我的母版页。内容页面中还有同名的超链接。因此,设置是在内容页上进行的,而不是在母版页上。更改母版页上的超链接名称后,它可以工作。

    ================================================ ======================

    您是否尝试过调试代码?当你到达时会发生什么

    temp_hyperlink.Text = myReader2("Text")
    

    i 的值是多少?

    myReader2("Text") 的值是多少?

    你找到temp_hyperlink的链接了吗?

    编辑: 即使html中没有任何内容,链接是否显示在页面上? 阅读器中 url 的价值是什么? 您是否尝试过使用 asp:linkbutton 代替?

    【讨论】:

    • 是的,我已经厌倦了调试它。问题是这个页面是我的母版页。内容页面中还有同名的超链接。因此,设置是在内容页上进行的,而不是在母版页上。更改母版页上的超链接名称后,它可以工作。非常感谢。
    • 你不需要将我的答案标记为答案,因为我没有解决它 - 你做到了!您可以添加自己的答案并将其标记为答案 - 然后其他有相同问题的人可以看到您如何解决它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 2010-10-07
    • 2014-07-08
    • 2010-09-15
    • 2021-08-27
    • 2014-02-04
    相关资源
    最近更新 更多