Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cross page post back problem

0 views
Skip to first unread message

WebBuilder451

unread,
Apr 29, 2008, 1:53:01 PM4/29/08
to
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

Scott M.

unread,
Apr 29, 2008, 2:21:22 PM4/29/08
to
Are you using MasterPages here?

"WebBuilder451" <WebBui...@discussions.microsoft.com> wrote in message
news:3D7D0D4D-9E5A-4BAD...@microsoft.com...

WebBuilder451

unread,
Apr 29, 2008, 2:32:03 PM4/29/08
to
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

Scott M.

unread,
Apr 29, 2008, 3:13:56 PM4/29/08
to
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" <WebBui...@discussions.microsoft.com> wrote in message

news:BA86E5D2-43B7-4173...@microsoft.com...

WebBuilder451

unread,
Apr 30, 2008, 8:53:00 AM4/30/08
to
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");

Scott M.

unread,
Apr 30, 2008, 4:42:34 PM4/30/08
to
Is page one (below) using a master page or just page 2?

-Scott


"WebBuilder451" <WebBui...@discussions.microsoft.com> wrote in message

news:6EAFC023-229E-4FE1...@microsoft.com...

WebBuilder451

unread,
Apr 30, 2008, 5:14:00 PM4/30/08
to
both use a single (same) master page (no nested masters).

Scott M.

unread,
Apr 30, 2008, 6:09:41 PM4/30/08
to
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" <WebBui...@discussions.microsoft.com> wrote in message

news:3ADA192E-8E5E-4AE2...@microsoft.com...

WebBuilder451

unread,
Apr 30, 2008, 9:11:22 PM4/30/08
to
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.

0 new messages