Showing posts with label master. Show all posts
Showing posts with label master. Show all posts

Thursday, March 29, 2012

Passing values across webforms that use Master pages

Sorry to create a new thread on an old post but I didn't get a viable answer
and thought that the odds were against me getting one unless I started a new
thread.

My question was this:

I want to pass a string variable from default3.aspx to default2.aspx.

I create a property in default2.aspx, called "X", and assign a value. I then
call Server.Transfer("default3.aspx")

In default3.aspx I have this code:
Dim Default3 As Default3 = ctype(Context.Handler, Default3)
Dim PassedString As String = Default3.x

This will work fine as long a default 3 is not a webform that references a
master page.

If it is, it tells me that "Default 3" is an undefined type. As a result,
the only way that I know o get it to work is to turn of Option Strict and
change it to this:

Dim Default3 As Object = Context.Handler
Dim PassedString As String = Default3.x

I really dont want to turn off Option Strict or resort to looselt typed
variables.

How do I correct this?
Chad,
Try either putting the String name=value combo on the querystring, or into
the HttpContext.Current.Items Collection. Not reasonable to expect a
"property" of a page to survive a server.transfer or Response.Redirect.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

"Chad" wrote:

> Sorry to create a new thread on an old post but I didn't get a viable answer
> and thought that the odds were against me getting one unless I started a new
> thread.
> My question was this:
> I want to pass a string variable from default3.aspx to default2.aspx.
> I create a property in default2.aspx, called "X", and assign a value. I then
> call Server.Transfer("default3.aspx")
> In default3.aspx I have this code:
> Dim Default3 As Default3 = ctype(Context.Handler, Default3)
> Dim PassedString As String = Default3.x
> This will work fine as long a default 3 is not a webform that references a
> master page.
> If it is, it tells me that "Default 3" is an undefined type. As a result,
> the only way that I know o get it to work is to turn of Option Strict and
> change it to this:
> Dim Default3 As Object = Context.Handler
> Dim PassedString As String = Default3.x
> I really dont want to turn off Option Strict or resort to looselt typed
> variables.
> How do I correct this?
>
>
>
>
>
Actually, it does work if you define Default3 as an Object. I was trying to
strongly type the variable Default3 as an object of type "Default3" and it
did not recognize the class "Defaulyt3" outside of the Default3 class.

Try it. It does work.

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.nospammin.com> wrote in message
news:C28C574E-44C8-4903-B81A-8A970605CBAA@.microsoft.com...
> Chad,
> Try either putting the String name=value combo on the querystring, or into
> the HttpContext.Current.Items Collection. Not reasonable to expect a
> "property" of a page to survive a server.transfer or Response.Redirect.
> Peter
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
> "Chad" wrote:
>> Sorry to create a new thread on an old post but I didn't get a viable
>> answer
>> and thought that the odds were against me getting one unless I started a
>> new
>> thread.
>>
>> My question was this:
>>
>> I want to pass a string variable from default3.aspx to default2.aspx.
>>
>> I create a property in default2.aspx, called "X", and assign a value. I
>> then
>> call Server.Transfer("default3.aspx")
>>
>> In default3.aspx I have this code:
>> Dim Default3 As Default3 = ctype(Context.Handler, Default3)
>> Dim PassedString As String = Default3.x
>>
>> This will work fine as long a default 3 is not a webform that references
>> a
>> master page.
>>
>> If it is, it tells me that "Default 3" is an undefined type. As a result,
>> the only way that I know o get it to work is to turn of Option Strict and
>> change it to this:
>>
>> Dim Default3 As Object = Context.Handler
>> Dim PassedString As String = Default3.x
>>
>> I really dont want to turn off Option Strict or resort to looselt typed
>> variables.
>>
>> How do I correct this?
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>

Passing values across webforms that use Master pages

Sorry to create a new thread on an old post but I didn't get a viable answer
and thought that the odds were against me getting one unless I started a new
thread.
My question was this:
I want to pass a string variable from default3.aspx to default2.aspx.
I create a property in default2.aspx, called "X", and assign a value. I then
call Server.Transfer("default3.aspx")
In default3.aspx I have this code:
Dim Default3 As Default3 = ctype(Context.Handler, Default3)
Dim PassedString As String = Default3.x
This will work fine as long a default 3 is not a webform that references a
master page.
If it is, it tells me that "Default 3" is an undefined type. As a result,
the only way that I know o get it to work is to turn of Option Strict and
change it to this:
Dim Default3 As Object = Context.Handler
Dim PassedString As String = Default3.x
I really dont want to turn off Option Strict or resort to looselt typed
variables.
How do I correct this?Chad,
Try either putting the String name=value combo on the querystring, or into
the HttpContext.Current.Items Collection. Not reasonable to expect a
"property" of a page to survive a server.transfer or Response.Redirect.
Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Chad" wrote:

> Sorry to create a new thread on an old post but I didn't get a viable answ
er
> and thought that the odds were against me getting one unless I started a n
ew
> thread.
> My question was this:
> I want to pass a string variable from default3.aspx to default2.aspx.
> I create a property in default2.aspx, called "X", and assign a value. I th
en
> call Server.Transfer("default3.aspx")
> In default3.aspx I have this code:
> Dim Default3 As Default3 = ctype(Context.Handler, Default3)
> Dim PassedString As String = Default3.x
> This will work fine as long a default 3 is not a webform that references a
> master page.
> If it is, it tells me that "Default 3" is an undefined type. As a result,
> the only way that I know o get it to work is to turn of Option Strict and
> change it to this:
> Dim Default3 As Object = Context.Handler
> Dim PassedString As String = Default3.x
> I really dont want to turn off Option Strict or resort to looselt typed
> variables.
> How do I correct this?
>
>
>
>
>
>
Actually, it does work if you define Default3 as an Object. I was trying to
strongly type the variable Default3 as an object of type "Default3" and it
did not recognize the class "Defaulyt3" outside of the Default3 class.
Try it. It does work.
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.nospammin.com> wrote in message
news:C28C574E-44C8-4903-B81A-8A970605CBAA@.microsoft.com...
> Chad,
> Try either putting the String name=value combo on the querystring, or into
> the HttpContext.Current.Items Collection. Not reasonable to expect a
> "property" of a page to survive a server.transfer or Response.Redirect.
> Peter
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
> "Chad" wrote:
>

Monday, March 26, 2012

passing variable to new page with LinkButton

I need to pass a variable from a master page to a details page when a user clicks on a link in a DataList. Right now I have a link button, but I don't know how to put the variable into the link at runtime. Hopefully this is just a matter of syntax? How can I make this work?

<asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1">

<ItemTemplate><asp:LinkButtonID="NameLinkButton"runat="server"Text='<%# Eval("Name") %>'PostBackUrl="details.aspx?sponsorID={0}"Font-Bold="true"></asp:LinkButton>

...

</ItemTemplate></asp:DataList>

try this tutorial

Tuorial #4 Understanding Web Application State in the begnner section ofhttp://www.asp.net/learn/videos/default.aspx?tabid=63#howdoi

helped me out alot on understanding how to pass from one page to the other.

Ragscoon =<^_^>=


could you define a string variable and set it equal to the text property of your linkbutton (I'm assuming the text property will be the data item you want to pass to your other page). Then add that string variable to the querystring that will be passed to your other page.

I had to do something like you are doing, except it was a linkbutton in a gridview. It came out like this:

sLocationCode = grdLocationCode.DataKeys(iIndex).Item("ALCODE").ToString()
sCountryCode = grdLocationCode.DataKeys(iIndex).Item("ALCCODE").ToString()
Response.Redirect("LocationCodeDetail.aspx?" & sCountryCode & ";" & sLocationCode)

I believe this addresses your question.


Thanks for the responses. What I am asking is: what is the syntax for concatenating the destination URL with the variable that I want to pass (the sponsorID)?

If I use:

<

asp:HyperLinkID="NameLabel"runat="server"Text='<%# Eval("Sponsor") %>'NavigateUrl='myDetails.aspx?sponsorID=<%# Eval("SponsorID") %>'Font-Bold="true"></asp:HyperLink>

I get:

http://localhost:2097/myFolder/myDetails.aspx?sponsorID=<%#%20Eval("SponsorID")%20%>

It does not parse the SponsorID variable.


To clarify the last line in my previous message:

I get:

http://localhost:2097/myFolder/myDetails.aspx?sponsorID=<%#%20Eval("SponsorID")%20%>It does not parse the SponsorID variable.