如何访问标签到另一个页面 [英] How to access label into another page
问题描述
你好,
我想将一个页面标签控件访问到另一个页面中,您可以引导或发送任何代码片段吗?
Hello,
i want to access one page label control into another page can u guide or send any snippets
推荐答案
您可以将单独的标签保留在aspx页面中,并使用会话来传递页面之间的标签值.
假设第1页中的标签ID为"Label1",第2页中的标签ID为"Label2"
在页面1中,您将存储label1的值,然后再重定向到页面2.
You can keep seperate labels in your aspx pages and use session to pass the label value between pages.
Lets say the ID of label in page 1 is "Label1" and ID of label in page 2 is "Label2"
In Page 1 you will store the value of label1 before redirecting to Page 2.
Session["LabelValue"] = Label1.text;
Response.Redirect("Page2.aspx");
在第2页中,您可以从会话中检索值并将其分配给label2,如下所示
In page 2 you can retrieve the value from session and assign it to label2 as shown below
if (Session["LabelValue"] != null)
{
//get the Session value
Label2.text = Session["LabelValue"].ToString();
}
请参阅本文
将页面值传输到另一个页面 [
Refer this article
Transferring page values to another page[^]
你好,
尝试
Hi,
Try with
Page.PreviousPage.FindControls("YourcontrolId").Text
如果您的页面是回发页面并进入下一页,则上面的代码将起作用.如果标签不在父层次结构上,则可能需要遍历控件.
希望这对您有用,您需要检查控件的条件是否为null.直接调用 .Text 可能会导致ObjectReferenceException.
谢谢
-Amit Gajjar
If your page is postback and come to the next page then above code will work. You may need to iterate through the controls if your label is not on parent hierarchy.
Hope this should work for you, You need to check condition for your control is not null. Directly calling .Text may cause ObjectReferenceException.
Thanks
-Amit Gajjar
这篇关于如何访问标签到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!