开发者

After dynamic filling of <label text="DYANMIC"> DYANMIC</label> cannot retrieve the text again

I am dynamically filling the label4.text.. I hope to retrieve it for updating in the dbms

<asp:Label ID="Label4" runat="server"  Font-Bold="True" BackColor="#E3EAEB" 
 Height="25px" Width="300px"><%=Application.Get("topic").ToString()%></asp:Label>

In the above code I need to insert text="<%=Application.Get("topic").ToString()%&g开发者_JAVA技巧t; in the <label>tag but this cannot be possible due to syntax error or it cannot be done at all.

I have a linkbutton, by clicking on the link button can I retrieve the text of the label.

<asp:LinkButton ID="LinkButton2" runat="server" Font-Size="Smaller" 
 onclick="LinkButton2_Click">Post to Comment</asp:LinkButton>

protected void LinkButton2_Click(object sender, EventArgs e)
{
    string dumy=Label4.text.toString();
    // This is return a empty string..
}

Please let me know where I am going wrong.. or is there any other way of doing it... Since I am dynamically filling the label4.text.. how to retrieve it?


try this in your server-side code

    protected override void OnPreRender(System.EventArgs e)
    {
        base.OnPreRender(e);
        if (!IsPostBack)
        {
            Label4.Text = Convert.ToString(Application.Get("topic")); //might be null?
        }
    }

Then you should be able to pull the text from that Label in your LinkButton as you have it (capital "Text")

OR!! You could just set the dumy string directly to the Application.Get("topic")

If you don't have serverside code I would just do the latter suggestion and make a label on the page like this:

<label style="font-weight: bold; background: #e3eaeb; height: 25px; width: 300px;"><%=Application.Get("topic").ToString()%></label>

(might want to look into stylesheets and just add a class="mylabelstyle" attribute


You can use expression builders for this, we do this all the time.

see here

So after you create and register your expression builder you would do something like

<asp:label runat="server" Text='<%$ AppText : "something" %>' />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜