Accessing one page controls to an other page in asp.net 2.0

Posted by Bravi under ASP.NET on 9/15/2009 | Views : 12252 | Status : [Member] | Replies : 7
I have 3 pages like defalut.aspx,defalut1.aspx and defalut2.aspx so now i want to get defalut.aspx,defalut1.aspx contrlos data in defalut2.aspx page...without using querystring,session...objects..




Responses

Posted by: Vuyiswamb on: 9/15/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Bravi

There are two Options the first one you can put the value of those controls in a Session variable and access them in another page. But if there are a lot of Controls in other page, then you can create a usercontrol , then in a usercontrol you can expose the values of those controls to the Hosting page and they can be accessed anywhere.

Thank you for posting at dotnetfunda


Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bravi on: 9/15/2009 [Member] Starter

Up
0
Down
Hi Vuyiswa
Goodmorning...

Thanks for your reply
i think we can slove above senario using cross page concept ..i tryed also but it is given me some errors..

if u d'not mide can u provid example on cross page postback

ThanX
Ravi B

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/15/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Bravi

That is another options. here is an Example of the Crosspage

if (Page.PreviousPage != null)
{
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox1");
if (SourceTextBox != null)
{
Label1.Text = SourceTextBox.Text;
}
}


as you can see , you need to check if the Previous page is still valid or available and then access its Controls using the FindControl method and use the Controls as if they are in the same page


Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bravi on: 9/16/2009 [Member] Starter

Up
0
Down
Hi Thanx for reply.

it is ok fine lets take in u r example TextBox1 is in first page then we can acess second page as per this code

if (Page.PreviousPage != null)
{
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox1");
if (SourceTextBox != null)
{
Label1.Text = SourceTextBox.Text;
}
}
but i need to access first and second page values in Third page using cross page please let me know

Thanx

Ravi

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/16/2009 [Member] [MVP] Bronze

Up
0
Down
It sounds to me like you are trying to build a multistep wizard.

There is a built in control which will allow you to do the multi staged process - and it automatically remembers the values of all the controls in the previous steps.

http://msdn.microsoft.com/en-us/magazine/cc163894.aspx

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/16/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
as Rtpharry said, it looks like you are doing a Wizard type of thing. Follow his Advice. use the Wizard Control its Very very Easy to use.

Thank you again for Posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/16/2009 [Member] [MVP] Bronze

Up
0
Down
You might also find my recent blog post about using named wizard steps handy as it shows a good way to manage referencing previous / future steps and how to find controls inside those steps.

http://runtingsproper.blogspot.com/2009/09/better-way-to-reference-your-wizard.html

Bravi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response