JasonWinn
asked on
Cross-Page Post Back problem
Hello,
I am simply trying to pull the information from one page to another. When I run my script I get this error:
Object reference not set to an instance of an object:
TextBox output = (TextBox)Page.PreviousPage .FindContr ol("compan yBox");
Thats the error, the following is a portion of my code:
<%@ PreviousPageType VirtualPath="~/default.asp x" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void submitButton_Click(object sender, EventArgs e)
{
TextBox output = (TextBox)Page.PreviousPage .FindContr ol("compan yBox");
notesBox.Text = "Hello, " + output.Text;
}
</script>
I am simply trying to pull the information from one page to another. When I run my script I get this error:
Object reference not set to an instance of an object:
TextBox output = (TextBox)Page.PreviousPage
Thats the error, the following is a portion of my code:
<%@ PreviousPageType VirtualPath="~/default.asp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void submitButton_Click(object sender, EventArgs e)
{
TextBox output = (TextBox)Page.PreviousPage
notesBox.Text = "Hello, " + output.Text;
}
</script>
I THINK ITS NOT POSSIBLE IN ASP.NET ... query string to get the values....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey Avanish,
Thank you for the reply.
I tried doing what you had but no go. First of all, it says .Value is invalid so I have been using .Text.
I am not getting any error messages, and notesBox.Text is displaying "Hello, " but it is not displaying hiddenCompany.Text's text.
any ideas? I will also include companyBox's code
statusNotifyMngment.aspx:
public void submitButton_Click(object sender, EventArgs e)
{
notesBox.Text = "Hello, " + hiddenCompany.Text;
}
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox output = (TextBox)Page.PreviousPage .FindContr ol("compan yBox");
//hidCompany hidden field to take previous page control value
hiddenCompany.Text = output.Text;
}
Default.Aspx:
<asp:TextBox ID="companyBox" runat="server" ></asp:TextBox>
<asp:Button ID="notifyButton" runat="server" Text="Notify" Width="74px" CssClass="button" PostBackUrl="~/statusNotif yMngment.a spx" />
Thank you for the reply.
I tried doing what you had but no go. First of all, it says .Value is invalid so I have been using .Text.
I am not getting any error messages, and notesBox.Text is displaying "Hello, " but it is not displaying hiddenCompany.Text's text.
any ideas? I will also include companyBox's code
statusNotifyMngment.aspx:
public void submitButton_Click(object sender, EventArgs e)
{
notesBox.Text = "Hello, " + hiddenCompany.Text;
}
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox output = (TextBox)Page.PreviousPage
//hidCompany hidden field to take previous page control value
hiddenCompany.Text = output.Text;
}
Default.Aspx:
<asp:TextBox ID="companyBox" runat="server" ></asp:TextBox>
<asp:Button ID="notifyButton" runat="server" Text="Notify" Width="74px" CssClass="button" PostBackUrl="~/statusNotif
ASKER
Update:
I have changed around some things but still not working. Looking for any help possible.
My textbox is showing "Didnt work" when I run this. I am using public properties on the 1st page
Default.aspx
<script runat="server">
public String CurrentCompany
{
get
{
return companyBox.Text;
}
}
</script>
statusNotifyMngment.aspx: (page 2)
if (PreviousPage != null && PreviousPage.IsCrossPagePo stBack)
{
notesBox.Text = PreviousPage.CurrentCompan y.ToString ();
}
else
{
// if previous Page is NULL just redirect us
notesBox.Text = "Didnt Work";
}
I have changed around some things but still not working. Looking for any help possible.
My textbox is showing "Didnt work" when I run this. I am using public properties on the 1st page
Default.aspx
<script runat="server">
public String CurrentCompany
{
get
{
return companyBox.Text;
}
}
</script>
statusNotifyMngment.aspx: (page 2)
if (PreviousPage != null && PreviousPage.IsCrossPagePo
{
notesBox.Text = PreviousPage.CurrentCompan
}
else
{
// if previous Page is NULL just redirect us
notesBox.Text = "Didnt Work";
}
ASKER
Small mistake, I did not mean to include ToString in the IF Statement. WIthout ToString() it still does not work