cross page post back problem

  • Thread starter Thread starter WebBuilder451
  • Start date Start date
W

WebBuilder451

I the page knows there was a cross post back. but i can not find the control.
(asp.net 3.5)

calling page has a master

calling control:
<asp:Button ID="btnSendAlert" runat="server" Text="Go"
onclick="btnSendAlert_Click" PostBackUrl="ItemUpLoadAdmin.aspx"
CommandArgument="5" />

receiving page
if (PreviousPage != null)
{

Button btn = (Button)PreviousPage.FindControl("btnSendAlert");
Response.Write(btn.Text); <--- errors here with null reference
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
yes

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
The problem is that when you have content in a contentpage, the ID's of the
rendered controls are not the same as what you named them. You should use
the ClientID property to identify it. But, since the control is from the
previous page, you'll need to pass the clientID to the new page, which you
can do via a crosspagepostback property as in:

[source page]

public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
[.aspx destination page]

Make sure that a reference to the previous page is declared at the top like
this:

<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>

[.aspx.cs destination page]

if (PreviousPage != null)
{
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
Response.Write(btn.Text);
}


Good luck!

-Scott
 
Hi Scott,
I'm getting the id across now, but i still can not find the control. I'm
running in 2k8 debug if that some how causes issues. I appreciate your help.
just to make sure i'm doing this correctly:

page on in sub directory with master:
public partial class Admin_x : System.Web.UI.Page
{
public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
protected void Page_Load(object sender, EventArgs e)
{

}
}

page 2 header with reference:
<%@ Page Language="C#" MasterPageFile="~/Admin/adminMasterPage.master"
AutoEventWireup="true" CodeFile="y.aspx.cs" Inherits="Admin_y"
Title="Untitled Page" %>
<%@ PreviousPageType VirtualPath="~/Admin/x.aspx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

page 2 code behind:
public partial class Admin_y : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
Response.Write(PreviousPage.ButtonClientID.ToString());
Response.Write("<BR />");
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
if (btn == null)
Response.Write("NG");
else
Response.Write("OK");
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
The problem is that when you have content in a contentpage, the ID's of the
rendered controls are not the same as what you named them. You should use
the ClientID property to identify it. But, since the control is from the
previous page, you'll need to pass the clientID to the new page, which you
can do via a crosspagepostback property as in:

[source page]

public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
[.aspx destination page]

Make sure that a reference to the previous page is declared at the top like
this:

<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>

[.aspx.cs destination page]

if (PreviousPage != null)
{
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
Response.Write(btn.Text);
}


Good luck!

-Scott

WebBuilder451 said:
yes

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
Is page one (below) using a master page or just page 2?

-Scott


WebBuilder451 said:
Hi Scott,
I'm getting the id across now, but i still can not find the control. I'm
running in 2k8 debug if that some how causes issues. I appreciate your
help.
just to make sure i'm doing this correctly:

page on in sub directory with master:
public partial class Admin_x : System.Web.UI.Page
{
public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
protected void Page_Load(object sender, EventArgs e)
{

}
}

page 2 header with reference:
<%@ Page Language="C#" MasterPageFile="~/Admin/adminMasterPage.master"
AutoEventWireup="true" CodeFile="y.aspx.cs" Inherits="Admin_y"
Title="Untitled Page" %>
<%@ PreviousPageType VirtualPath="~/Admin/x.aspx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

page 2 code behind:
public partial class Admin_y : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
Response.Write(PreviousPage.ButtonClientID.ToString());
Response.Write("<BR />");
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
if (btn == null)
Response.Write("NG");
else
Response.Write("OK");
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
The problem is that when you have content in a contentpage, the ID's of
the
rendered controls are not the same as what you named them. You should
use
the ClientID property to identify it. But, since the control is from the
previous page, you'll need to pass the clientID to the new page, which
you
can do via a crosspagepostback property as in:

[source page]

public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
[.aspx destination page]

Make sure that a reference to the previous page is declared at the top
like
this:

<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>

[.aspx.cs destination page]

if (PreviousPage != null)
{
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
Response.Write(btn.Text);
}


Good luck!

-Scott

message
yes

--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


:

Are you using MasterPages here?



message
I the page knows there was a cross post back. but i can not find the
control.
(asp.net 3.5)

calling page has a master

calling control:
<asp:Button ID="btnSendAlert" runat="server" Text="Go"
onclick="btnSendAlert_Click"
PostBackUrl="ItemUpLoadAdmin.aspx"
CommandArgument="5" />

receiving page
if (PreviousPage != null)
{

Button btn =
(Button)PreviousPage.FindControl("btnSendAlert");
Response.Write(btn.Text); <--- errors here with null
reference
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler
than
vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
both use a single (same) master page (no nested masters).

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
Is page one (below) using a master page or just page 2?

-Scott


WebBuilder451 said:
Hi Scott,
I'm getting the id across now, but i still can not find the control. I'm
running in 2k8 debug if that some how causes issues. I appreciate your
help.
just to make sure i'm doing this correctly:

page on in sub directory with master:
public partial class Admin_x : System.Web.UI.Page
{
public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
protected void Page_Load(object sender, EventArgs e)
{

}
}

page 2 header with reference:
<%@ Page Language="C#" MasterPageFile="~/Admin/adminMasterPage.master"
AutoEventWireup="true" CodeFile="y.aspx.cs" Inherits="Admin_y"
Title="Untitled Page" %>
<%@ PreviousPageType VirtualPath="~/Admin/x.aspx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

page 2 code behind:
public partial class Admin_y : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
Response.Write(PreviousPage.ButtonClientID.ToString());
Response.Write("<BR />");
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
if (btn == null)
Response.Write("NG");
else
Response.Write("OK");
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
The problem is that when you have content in a contentpage, the ID's of
the
rendered controls are not the same as what you named them. You should
use
the ClientID property to identify it. But, since the control is from the
previous page, you'll need to pass the clientID to the new page, which
you
can do via a crosspagepostback property as in:

[source page]

public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
[.aspx destination page]

Make sure that a reference to the previous page is declared at the top
like
this:

<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>

[.aspx.cs destination page]

if (PreviousPage != null)
{
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
Response.Write(btn.Text);
}


Good luck!

-Scott

message
yes

--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


:

Are you using MasterPages here?



message
I the page knows there was a cross post back. but i can not find the
control.
(asp.net 3.5)

calling page has a master

calling control:
<asp:Button ID="btnSendAlert" runat="server" Text="Go"
onclick="btnSendAlert_Click"
PostBackUrl="ItemUpLoadAdmin.aspx"
CommandArgument="5" />

receiving page
if (PreviousPage != null)
{

Button btn =
(Button)PreviousPage.FindControl("btnSendAlert");
Response.Write(btn.Text); <--- errors here with null
reference
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler
than
vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
So, let me make sure I understand, you are now able to get the actual
clientID of your button on page 2 (you can confirm this by not only looking
at the response.write, but also by looking at the rendered source code and
find the control yourself), but the page 2 code doesn't locate the control
with the FindControl method?

-Scott

WebBuilder451 said:
both use a single (same) master page (no nested masters).

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
Is page one (below) using a master page or just page 2?

-Scott


message
Hi Scott,
I'm getting the id across now, but i still can not find the control.
I'm
running in 2k8 debug if that some how causes issues. I appreciate your
help.
just to make sure i'm doing this correctly:

page on in sub directory with master:
public partial class Admin_x : System.Web.UI.Page
{
public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
protected void Page_Load(object sender, EventArgs e)
{

}
}

page 2 header with reference:
<%@ Page Language="C#" MasterPageFile="~/Admin/adminMasterPage.master"
AutoEventWireup="true" CodeFile="y.aspx.cs" Inherits="Admin_y"
Title="Untitled Page" %>
<%@ PreviousPageType VirtualPath="~/Admin/x.aspx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

page 2 code behind:
public partial class Admin_y : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
Response.Write(PreviousPage.ButtonClientID.ToString());
Response.Write("<BR />");
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
if (btn == null)
Response.Write("NG");
else
Response.Write("OK");
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


:

The problem is that when you have content in a contentpage, the ID's
of
the
rendered controls are not the same as what you named them. You should
use
the ClientID property to identify it. But, since the control is from
the
previous page, you'll need to pass the clientID to the new page, which
you
can do via a crosspagepostback property as in:

[source page]

public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
[.aspx destination page]

Make sure that a reference to the previous page is declared at the top
like
this:

<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>

[.aspx.cs destination page]

if (PreviousPage != null)
{
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
Response.Write(btn.Text);
}


Good luck!

-Scott

message
yes

--
(i''ll be asking a lot of these, but I find C# totally way cooler
than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


:

Are you using MasterPages here?



message
I the page knows there was a cross post back. but i can not find
the
control.
(asp.net 3.5)

calling page has a master

calling control:
<asp:Button ID="btnSendAlert" runat="server" Text="Go"
onclick="btnSendAlert_Click"
PostBackUrl="ItemUpLoadAdmin.aspx"
CommandArgument="5" />

receiving page
if (PreviousPage != null)
{

Button btn =
(Button)PreviousPage.FindControl("btnSendAlert");
Response.Write(btn.Text); <--- errors here with
null
reference
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler
than
vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
yes, odd as this seems. I even created a value specificly get,set to add to
the posted page and this is found directly so that Previouspage.iMyID will
give the id i set in page 1. I'll end up using this, but it's odd that find
control is not finding!!!

(you can confirm this by not only looking
at the response.write, but also by looking at the rendered source code and
find the control yourself) Have not confirmed that the control is there, but intelesense get the value it writes.

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
So, let me make sure I understand, you are now able to get the actual
clientID of your button on page 2 (you can confirm this by not only looking
at the response.write, but also by looking at the rendered source code and
find the control yourself), but the page 2 code doesn't locate the control
with the FindControl method?

-Scott

WebBuilder451 said:
both use a single (same) master page (no nested masters).

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Scott M. said:
Is page one (below) using a master page or just page 2?

-Scott


message
Hi Scott,
I'm getting the id across now, but i still can not find the control.
I'm
running in 2k8 debug if that some how causes issues. I appreciate your
help.
just to make sure i'm doing this correctly:

page on in sub directory with master:
public partial class Admin_x : System.Web.UI.Page
{
public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
protected void Page_Load(object sender, EventArgs e)
{

}
}

page 2 header with reference:
<%@ Page Language="C#" MasterPageFile="~/Admin/adminMasterPage.master"
AutoEventWireup="true" CodeFile="y.aspx.cs" Inherits="Admin_y"
Title="Untitled Page" %>
<%@ PreviousPageType VirtualPath="~/Admin/x.aspx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
</asp:Content>

page 2 code behind:
public partial class Admin_y : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
Response.Write(PreviousPage.ButtonClientID.ToString());
Response.Write("<BR />");
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
if (btn == null)
Response.Write("NG");
else
Response.Write("OK");
}
}
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


:

The problem is that when you have content in a contentpage, the ID's
of
the
rendered controls are not the same as what you named them. You should
use
the ClientID property to identify it. But, since the control is from
the
previous page, you'll need to pass the clientID to the new page, which
you
can do via a crosspagepostback property as in:

[source page]

public String ButtonClientID
{
get
{
return btnSendAlert.ClientID;
}
}
[.aspx destination page]

Make sure that a reference to the previous page is declared at the top
like
this:

<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>

[.aspx.cs destination page]

if (PreviousPage != null)
{
Button btn =
(Button)PreviousPage.FindControl(PreviousPage.ButtonClientID);
Response.Write(btn.Text);
}


Good luck!

-Scott

message
yes

--
(i''ll be asking a lot of these, but I find C# totally way cooler
than
vb
and there''s no go''n back!!!)
thanks (as always)

kes


:

Are you using MasterPages here?



message
I the page knows there was a cross post back. but i can not find
the
control.
(asp.net 3.5)

calling page has a master

calling control:
<asp:Button ID="btnSendAlert" runat="server" Text="Go"
onclick="btnSendAlert_Click"
PostBackUrl="ItemUpLoadAdmin.aspx"
CommandArgument="5" />

receiving page
if (PreviousPage != null)
{

Button btn =
(Button)PreviousPage.FindControl("btnSendAlert");
Response.Write(btn.Text); <--- errors here with
null
reference
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler
than
vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
Back
Top