我如何找到其他页面的标签控制 [英] How Can i Find Label Control Of Other Page
问题描述
这是我的源代码
Here is my Source code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
<%@ PreviousPageType VirtualPath="Default3.aspx"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="Js/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Js/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script language ="javascript" >
function f3() {
$("#shibashish").load("Default3.aspx", {}, function () { });
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button
ID="Button4" runat="server" Text="Third" onclick="Button4_Click" />
<asp:Button ID="Button3" runat="server" Text="Effect" onclick="Button3_Click" />
<asp:Label ID="Label1" style="padding-left:1000px;" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<br />
Hi this is static
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
</ProgressTemplate>
</asp:UpdateProgress>
<br />
<div id="shibashish">
hi this dynamic
</div>
</div>
</form>
</body>
</html>
这是我的代码背后
Here is my code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
Default3 page1 = PreviousPage as Default3;
if (page1 != null)
{
Label lbl = (Label)PreviousPage.FindControl("LblTest");
Label1.Text = lbl.Text;
}
}
protected void Button4_Click(object sender, EventArgs e)
{
string script = "<script language=" + "'javascript'" + ">f3();</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), script, false);
}
}
现在请帮帮我如何找到标签Default3.aspx页面
这里是我的default3.aspx源代码和设置default4.aspx标签值作为该页面标签值
Now please help me How to find the Label of Default3.aspx page
here is my default3.aspx source code and Set default4.aspx label value as that page label value
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="LblTest" runat="server" Text="om namah shivaya"></asp:Label>
</div>
</form>
</body>
</html>
先谢谢
Thanks in Advance
推荐答案
( #shibashish)。 ( Default3.aspx,{}, function (){ });
}
< / 脚本 >
< / head >
< body >
< 表单 id = form1 runat < span class =code-keyword> = server >
< asp:ScriptManager ID = ScriptManager1 runat = < span class =code-keyword> server >
< / asp:ScriptManager >
< ; div >
< asp:UpdatePanel ID = UpdatePanel1 runat = server >
< ContentTemplate >
< < span class =code-leadattribute> asp:Button
ID = Button4 runat = server 文字 = 第三个 onclick = Button4_Click / >
< asp:按钮 ID = Button3 runat = server文字 = Effect onclick = Button3_Click / >
< asp:Label ID = Label1 style = padding-left:1000px; runat = server 文本 = 标签 > < / asp:Label >
< < span class =code-leadattribute> / ContentTemplate >
< / asp:UpdatePanel >
< br / >
这是静态的
< asp:UpdateProgress ID = UpdateProgress1 runat = 服务器 >
< ProgressTemplate >
& nbsp;
< / ProgressTemplate >
< / asp:UpdateProgress >
< br / >
< div id = shibashish >
此动态
< span class =code-keyword>< / div >
< / div >
< / form >
< / body >
< / html >
("#shibashish").load("Default3.aspx", {}, function () { }); } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button4" runat="server" Text="Third" onclick="Button4_Click" /> <asp:Button ID="Button3" runat="server" Text="Effect" onclick="Button3_Click" /> <asp:Label ID="Label1" style="padding-left:1000px;" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> <br /> Hi this is static <asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> </ProgressTemplate> </asp:UpdateProgress> <br /> <div id="shibashish"> hi this dynamic </div> </div> </form> </body> </html>
这是我的代码背后
Here is my code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
Default3 page1 = PreviousPage as Default3;
if (page1 != null)
{
Label lbl = (Label)PreviousPage.FindControl("LblTest");
Label1.Text = lbl.Text;
}
}
protected void Button4_Click(object sender, EventArgs e)
{
string script = "<script language=" + "'javascript'" + ">f3();</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), script, false);
}
}
现在请帮帮我如何找到标签Default3.aspx页面
这里是我的default3.aspx源代码和设置default4.aspx标签值作为该页面标签值
Now please help me How to find the Label of Default3.aspx page
here is my default3.aspx source code and Set default4.aspx label value as that page label value
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="LblTest" runat="server" Text="om namah shivaya"></asp:Label>
</div>
</form>
</body>
</html>
Thanks in Advance
Thanks in Advance
Create the a public function of the control in the page where it is placed function like this in your case
Create the a public function of the control in the page where it is placed function like this in your case
public label getlable()
{
return LblTest;
}
And in the page you want to access this label you should do like this
And in the page you want to access this label you should do like this
Default3 df3 = ((default3)(page));
df3.getlablel().text = "assign the value";
each properties of the LblTest is avail able here
hope it will help you .
each properties of the LblTest is avail able here
hope it will help you .
1. set the PostBackUrl property of the Button to the New Page
1. set the PostBackUrl property of the Button to the New Page
<asp:button id="Button1" runat="server" text="test now " postbackurl="~/Default5.aspx" xmlns:asp="#unknown" />
or you can use
<asp:button id=\"Button1\" runat=\"server\" text=\"test now \" xmlns:asp=\"#unknown\">
onclick=\"Button1_Click2\" />
code behind
Hi ,
Try this
or you can use
<asp:button id="Button1" runat="server" text="test now " xmlns:asp="#unknown">
onclick="Button1_Click2" />
code behind
Hi ,
Try this
protected void Button1_Click2(object sender, EventArgs e)
{
Server.Transfer("Default5.aspx");
}
Note : Response.Redirect(\"Default5.aspx\"); will raise
Error Object reference not set to an instance of an object.
in the the other page
Note : Response.Redirect("Default5.aspx"); will raise
Error Object reference not set to an instance of an object.
in the the other page
protected void Page_Load(object sender, EventArgs e)
{
// this is page Default5
if (!IsPostBack)
{
Button btn = ((Button)PreviousPage.FindControl("Button1"));
Button1.Text = btn.Text;
}
}
Best Regards
M.Mitwalli
Best Regards
M.Mitwalli
这篇关于我如何找到其他页面的标签控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!