Saturday, March 31, 2012

sensible way to pass around values

With .NET 1.x, this is what I did. On the destination page

public class ToWebForm : System.Web.UI.Page
{
public const string PARAMETER = "PARAM";
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
Response.Write(paramFromAnotherPage);
}
}
}

And on the source page
Context.Items.Add(ToWebForm.PARAMETER, "value");
Server.Transfer("ToWebForm.aspx");

Basically I am creating an interface (not in a .net sense) on the
destination page so that the source page can simply use the string
constant as the name of the parameter.

..NET 2.0 does not seem to be happy with this. The funny thing is,
sometimes it works, and sometimes it does not even compile, which I
find very frustrating.

Is there any reason why this won't work well with partial classes?

And what is the sensible way to pass values from page to page without
having to copy and past the parameter names all over the web project?..NET 2.0 is "last page aware". Try this:
http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
"David C" <profnachos@.gmail.comwrote in message
news:1186434005.231509.3920@.z24g2000prh.googlegrou ps.com...

Quote:

Originally Posted by

With .NET 1.x, this is what I did. On the destination page
>
public class ToWebForm : System.Web.UI.Page
{
public const string PARAMETER = "PARAM";
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
Response.Write(paramFromAnotherPage);
}
}
}
>
And on the source page
Context.Items.Add(ToWebForm.PARAMETER, "value");
Server.Transfer("ToWebForm.aspx");
>
Basically I am creating an interface (not in a .net sense) on the
destination page so that the source page can simply use the string
constant as the name of the parameter.
>
.NET 2.0 does not seem to be happy with this. The funny thing is,
sometimes it works, and sometimes it does not even compile, which I
find very frustrating.
>
Is there any reason why this won't work well with partial classes?
>
And what is the sensible way to pass values from page to page without
having to copy and past the parameter names all over the web project?
>


On Aug 7, 6:20 am, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@.comcast.netNoSpamMwrote:

Quote:

Originally Posted by

.NET 2.0 is "last page aware". Try this:http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
>
>


Thank you very much. I was pleasantly surprised to see that it even
reads the ViewState of the previous page.
Is there anyway to enable this for a gridview? Perhaps a user control or a
hidden button?

Ross

"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamMwrote in
message news:%234TxnWP2HHA.3940@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

.NET 2.0 is "last page aware". Try this:
http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)
>
************************************************
Think outside the box!
************************************************
"David C" <profnachos@.gmail.comwrote in message
news:1186434005.231509.3920@.z24g2000prh.googlegrou ps.com...

Quote:

Originally Posted by

>With .NET 1.x, this is what I did. On the destination page
>>
>public class ToWebForm : System.Web.UI.Page
>{
>public const string PARAMETER = "PARAM";
>protected void Page_Load(object sender, System.EventArgs e)
>{
>if (!IsPostBack)
>{
>string paramFromAnotherPage = Context.Items[PARAMETER].ToString();
>Response.Write(paramFromAnotherPage);
>}
>}
>}
>>
>And on the source page
> Context.Items.Add(ToWebForm.PARAMETER, "value");
> Server.Transfer("ToWebForm.aspx");
>>
>Basically I am creating an interface (not in a .net sense) on the
>destination page so that the source page can simply use the string
>constant as the name of the parameter.
>>
>.NET 2.0 does not seem to be happy with this. The funny thing is,
>sometimes it works, and sometimes it does not even compile, which I
>find very frustrating.
>>
>Is there any reason why this won't work well with partial classes?
>>
>And what is the sensible way to pass values from page to page without
>having to copy and past the parameter names all over the web project?
>>


>
>

0 comments:

Post a Comment