开发者

Page.DataBind() conflict

开发者 https://www.devze.com 2023-02-12 16:08 出处:网络
I have master web page and html code which publish string from the AddThis class. MainMasterPage.master

I have master web page and html code which publish string from the AddThis class.

MainMasterPage.master

<div class="add-this">
    <%# AddThis.Publish %>                                  
</div>

AddThis.cs Class code

public static class AddThis
{
    public static string Publish
    {

        get
        {
            return

                "<div class='addthis_toolbox addthis_default_style'>" +
                "<a class='addthis_button_delicious'></a>" +
                "<a class='addthis_button_digg'></a>" +
                "<a class='addthis_button_stumbleupon'></a>" +
                "<a class='addthis_button_facebook'></a>" +
                "<a class='addthis_button_twitter'></a>" +
                "<a class='addthis_button_googlebuzz'></a>" +
                "<a class='addthis_button_email'></a>" +
                "<a class='addthis_button_blogger'></a>" +
                "<a class='addthis_button_compact'></a>" +
                "<span class='addthis_separator'> </span>" +
                "<a class='addthis_button_facebook_like'></a>" +
                "</div>" +
                "<script type='text/javascript' src='http://s7.addthis.com/js/250/addthis_widget.js#username=tomasr'></script>";

        }

    }
}

To bind <%# AddThis.Publish %> tag and execute class code I add DataBind to master web page code like this

MainMasterPage.master.cs

protected void Page_Load(object sender, EventArgs e)
{
   Page.DataBind();
}

The problem is that my main master web page(MainMasterPage.master) is nested and used in 3rd party forum application and I get error below when forum web pages are executed. It seems that DataBind code which is in MainMasterPage.master bind controls in forum code before they are initialized. The question would be, how to bind my AddThis tag in all web pages but without binding other objects?

Invalid attempt to call FieldCount when reader is closed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stac开发者_JS百科k trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Invalid attempt to call FieldCount when reader is closed.

Source Error: 


Line 58: 
Line 59:         
Line 60:         Page.DataBind();
Line 61: 
Line 62:     }


In All Honesty. I personally would use a Literal on the Page and set the .Text of the Literal to the AddThis.Publish Class

Literal1.Text = AddThis.Publish;

DataBinding using InLine code can be Damn Annoying

Other option is use

<%# Eval("AddThis.Publish") %> 

instead

0

精彩评论

暂无评论...
验证码 换一张
取 消