I want to create session objects for all web controls in a page. Right
now, I am doing it in a dumb way like this (for example):
Session("Session1") = ctrl1.Text
Session("Session2") = ctrl2.Text
Session("Session3") = ctrl3.Text
Session("Session4") = ctrl4.SelectedValue
Session("Session5") = ctrl5.Text
Session("Session6") = ctrl6.Text
It would be good if I can get all web controls and loop through them.
I searched this group and noticed that this topic has been discussed in
a few threads. But I've tried
For Each objCtrl in Page.FindControl("MyForm").Controls
and
For Each objCtrl In Page.Controls
and
For Each objCtrl In MyForm.Controls
and
For Each objCtrl In Me.Controls
None of them worked. Would any guru please share your idea? Thanks. 9 3319 an***********@yahoo.com wrote in news:1128447022.689767.319880
@o13g2000cwo.googlegroups.com: It would be good if I can get all web controls and loop through them. I searched this group and noticed that this topic has been discussed
in a few threads. But I've tried
For Each objCtrl in Page.FindControl("MyForm").Controls
and
For Each objCtrl In Page.Controls
and
For Each objCtrl In MyForm.Controls
and
For Each objCtrl In Me.Controls
None of them worked. Would any guru please share your idea? Thanks.
The above DO work - but what you have to do is create a recursive
function to loop through all the controls. This is because controls on
the page are nested:
Page Control
PlaceHolder Control
Table Control
Row Control
Cell Control
MY TEXT BOX CONTROL
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
Newmarket Volvo Sucks! http://newmarketvolvo.tripod.com
I'm cautious about given any help 'cuz your approach seems mad! Why in the
world would you ever want to do what you are doing?! We'll, I'll assume
you've thought it trough *shrug*.
public sub LoadIntoSession(byval parent as control, byref count as integer)
for each child as Control in Parent.Controls
count = count + 1
dim sessionKey as string = "Session" + count.ToString()
dim value as string
if typeof child is TextBox then
value = ctype(child, TextBox).Text
else if typeof child is ListControl then
value = ctype(child, DropDownList).SelectedValue
else if typeof child is ... ' youneed to do this for every type
..
end if
if child.HasControl then
LoadIntoSession(child, count)
end if
next
end sub
Page_Load
LoadIntoSession(Page, 0)
end sub
That code isn't perfect, but something like that should help...
I still think it's probably a bad design...whatever you are doing....
Server.Transfer w/preserve Form might work, or using the HttpContext....
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
<an***********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... I want to create session objects for all web controls in a page. Right now, I am doing it in a dumb way like this (for example):
Session("Session1") = ctrl1.Text Session("Session2") = ctrl2.Text Session("Session3") = ctrl3.Text Session("Session4") = ctrl4.SelectedValue Session("Session5") = ctrl5.Text Session("Session6") = ctrl6.Text
It would be good if I can get all web controls and loop through them. I searched this group and noticed that this topic has been discussed in a few threads. But I've tried
For Each objCtrl in Page.FindControl("MyForm").Controls
and
For Each objCtrl In Page.Controls
and
For Each objCtrl In MyForm.Controls
and
For Each objCtrl In Me.Controls
None of them worked. Would any guru please share your idea? Thanks.
First of all, thanks a lot for the sample code.
Secondly, do you mean that it is not a good idea to create a session
object for each web control?
I don't know if this is a good design or not, but my boss wants the
user-supplied data in web forms across multiple pages to be retained
while they jump around these pages.
So, I think that session is the best solution. If looping through all
web controls is troublesome, I'll just do it the dumb way: create a
session line after another.
Karl Seguin wrote: I'm cautious about given any help 'cuz your approach seems mad! Why in the world would you ever want to do what you are doing?! We'll, I'll assume you've thought it trough *shrug*.
public sub LoadIntoSession(byval parent as control, byref count as integer) for each child as Control in Parent.Controls count = count + 1 dim sessionKey as string = "Session" + count.ToString() dim value as string if typeof child is TextBox then value = ctype(child, TextBox).Text else if typeof child is ListControl then value = ctype(child, DropDownList).SelectedValue else if typeof child is ... ' youneed to do this for every type .. end if
if child.HasControl then LoadIntoSession(child, count) end if next end sub
Page_Load LoadIntoSession(Page, 0) end sub
That code isn't perfect, but something like that should help...
I still think it's probably a bad design...whatever you are doing.... Server.Transfer w/preserve Form might work, or using the HttpContext....
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...I want to create session objects for all web controls in a page. Right now, I am doing it in a dumb way like this (for example):
Session("Session1") = ctrl1.Text Session("Session2") = ctrl2.Text Session("Session3") = ctrl3.Text Session("Session4") = ctrl4.SelectedValue Session("Session5") = ctrl5.Text Session("Session6") = ctrl6.Text
It would be good if I can get all web controls and loop through them. I searched this group and noticed that this topic has been discussed in a few threads. But I've tried
For Each objCtrl in Page.FindControl("MyForm").Controls
and
For Each objCtrl In Page.Controls
and
For Each objCtrl In MyForm.Controls
and
For Each objCtrl In Me.Controls
None of them worked. Would any guru please share your idea? Thanks.
Well, it's just going to lead to a cumbersome and complex design, in my
opinion.
Either use Server.Transfer and PreserveForm
( http://msdn.microsoft.com/library/de...sferTopic2.asp)
which will maintain REquest.Form so atleast it's only 1/2 as hackish...or
better yet...
create a business object and passthat in your session.
Say you are building a user registration thing with 3 pages, page 1 : basic
information, page 2: address, page 3: membership details
Page 1 -->
sub btnPage2_Clicked
dim user as new User()
user.Name = UserName.Text
user.Email= Email.Text
user.Country= Country.SelectedValue
Session("NewUser") = user
Response.Redirect("Page2.aspx")
end sub
Page 2 -->
dim user as User = ctype(Session("NewUser"), User)
if user is nothing then
'error, has to start on page 1
end if
user.Telephone = telephone.TExt
...
..
Response.Redirect("Page2.aspx")
end sub
or you could just store the user in Context.ITems and use a Server.Transfer.
Anyways, it's similar to what you are doing, but it's better encapsulated.
You aren't passing 100 pieces of free floating information around, but
rather passing a single object and building it up....assuming that's
applicable to what you are doing.
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
<an***********@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... First of all, thanks a lot for the sample code.
Secondly, do you mean that it is not a good idea to create a session object for each web control?
I don't know if this is a good design or not, but my boss wants the user-supplied data in web forms across multiple pages to be retained while they jump around these pages.
So, I think that session is the best solution. If looping through all web controls is troublesome, I'll just do it the dumb way: create a session line after another.
Karl Seguin wrote: I'm cautious about given any help 'cuz your approach seems mad! Why in the world would you ever want to do what you are doing?! We'll, I'll assume you've thought it trough *shrug*.
public sub LoadIntoSession(byval parent as control, byref count as integer) for each child as Control in Parent.Controls count = count + 1 dim sessionKey as string = "Session" + count.ToString() dim value as string if typeof child is TextBox then value = ctype(child, TextBox).Text else if typeof child is ListControl then value = ctype(child, DropDownList).SelectedValue else if typeof child is ... ' youneed to do this for every type .. end if
if child.HasControl then LoadIntoSession(child, count) end if next end sub
Page_Load LoadIntoSession(Page, 0) end sub
That code isn't perfect, but something like that should help...
I still think it's probably a bad design...whatever you are doing.... Server.Transfer w/preserve Form might work, or using the HttpContext....
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... >I want to create session objects for all web controls in a page. Right > now, I am doing it in a dumb way like this (for example): > > Session("Session1") = ctrl1.Text > Session("Session2") = ctrl2.Text > Session("Session3") = ctrl3.Text > Session("Session4") = ctrl4.SelectedValue > Session("Session5") = ctrl5.Text > Session("Session6") = ctrl6.Text > > It would be good if I can get all web controls and loop through them. > I searched this group and noticed that this topic has been discussed in > a few threads. But I've tried > > For Each objCtrl in Page.FindControl("MyForm").Controls > > and > > For Each objCtrl In Page.Controls > > and > > For Each objCtrl In MyForm.Controls > > and > > For Each objCtrl In Me.Controls > > None of them worked. Would any guru please share your idea? Thanks. >
Hi,
Thanks a lot. Sounds like that is a much better way than session to
achieve my goal. However, I still don't know anything about that yet.
Actually, a few days ago, I asked in this group if there is a better
way than session, here: http://groups.google.com/group/micro...56748848a2d36d
The MSDN link is helpful, but I cannot jumpstart from that brief doc.
Could you point me to some more detailed documentation about how to
implement this?
Thanks.
Karl Seguin wrote: Well, it's just going to lead to a cumbersome and complex design, in my opinion.
Either use Server.Transfer and PreserveForm (http://msdn.microsoft.com/library/de...sferTopic2.asp) which will maintain REquest.Form so atleast it's only 1/2 as hackish...or better yet...
create a business object and passthat in your session.
Say you are building a user registration thing with 3 pages, page 1 : basic information, page 2: address, page 3: membership details
Page 1 -->
sub btnPage2_Clicked dim user as new User() user.Name = UserName.Text user.Email= Email.Text user.Country= Country.SelectedValue Session("NewUser") = user Response.Redirect("Page2.aspx") end sub
Page 2 --> dim user as User = ctype(Session("NewUser"), User) if user is nothing then 'error, has to start on page 1 end if user.Telephone = telephone.TExt ... .. Response.Redirect("Page2.aspx") end sub
or you could just store the user in Context.ITems and use a Server.Transfer.
Anyways, it's similar to what you are doing, but it's better encapsulated. You aren't passing 100 pieces of free floating information around, but rather passing a single object and building it up....assuming that's applicable to what you are doing.
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com... First of all, thanks a lot for the sample code.
Secondly, do you mean that it is not a good idea to create a session object for each web control?
I don't know if this is a good design or not, but my boss wants the user-supplied data in web forms across multiple pages to be retained while they jump around these pages.
So, I think that session is the best solution. If looping through all web controls is troublesome, I'll just do it the dumb way: create a session line after another.
Karl Seguin wrote: I'm cautious about given any help 'cuz your approach seems mad! Why in the world would you ever want to do what you are doing?! We'll, I'll assume you've thought it trough *shrug*.
public sub LoadIntoSession(byval parent as control, byref count as integer) for each child as Control in Parent.Controls count = count + 1 dim sessionKey as string = "Session" + count.ToString() dim value as string if typeof child is TextBox then value = ctype(child, TextBox).Text else if typeof child is ListControl then value = ctype(child, DropDownList).SelectedValue else if typeof child is ... ' youneed to do this for every type .. end if
if child.HasControl then LoadIntoSession(child, count) end if next end sub
Page_Load LoadIntoSession(Page, 0) end sub
That code isn't perfect, but something like that should help...
I still think it's probably a bad design...whatever you are doing.... Server.Transfer w/preserve Form might work, or using the HttpContext....
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... >I want to create session objects for all web controls in a page. Right > now, I am doing it in a dumb way like this (for example): > > Session("Session1") = ctrl1.Text > Session("Session2") = ctrl2.Text > Session("Session3") = ctrl3.Text > Session("Session4") = ctrl4.SelectedValue > Session("Session5") = ctrl5.Text > Session("Session6") = ctrl6.Text > > It would be good if I can get all web controls and loop through them. > I searched this group and noticed that this topic has been discussed in > a few threads. But I've tried > > For Each objCtrl in Page.FindControl("MyForm").Controls > > and > > For Each objCtrl In Page.Controls > > and > > For Each objCtrl In MyForm.Controls > > and > > For Each objCtrl In Me.Controls > > None of them worked. Would any guru please share your idea? Thanks. >
Well, if you only need the data to exist while a user hits next> next> next>
or <prev <prev <prev, you could do:
dim user as new User()
.....
Context.Items.Add("NewUser", user)
Server.Transfer("Page2.aspx")
and then you can retrieve the user from Page2.aspx ala:
dim user as User = ctype(Context.Items("NewUser", User")
'don't forget to check for nothing..
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
<an***********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
Thanks a lot. Sounds like that is a much better way than session to achieve my goal. However, I still don't know anything about that yet.
Actually, a few days ago, I asked in this group if there is a better way than session, here:
http://groups.google.com/group/micro...56748848a2d36d
The MSDN link is helpful, but I cannot jumpstart from that brief doc. Could you point me to some more detailed documentation about how to implement this?
Thanks.
Karl Seguin wrote: Well, it's just going to lead to a cumbersome and complex design, in my opinion.
Either use Server.Transfer and PreserveForm (http://msdn.microsoft.com/library/de...sferTopic2.asp) which will maintain REquest.Form so atleast it's only 1/2 as hackish...or better yet...
create a business object and passthat in your session.
Say you are building a user registration thing with 3 pages, page 1 : basic information, page 2: address, page 3: membership details
Page 1 -->
sub btnPage2_Clicked dim user as new User() user.Name = UserName.Text user.Email= Email.Text user.Country= Country.SelectedValue Session("NewUser") = user Response.Redirect("Page2.aspx") end sub
Page 2 --> dim user as User = ctype(Session("NewUser"), User) if user is nothing then 'error, has to start on page 1 end if user.Telephone = telephone.TExt ... .. Response.Redirect("Page2.aspx") end sub
or you could just store the user in Context.ITems and use a Server.Transfer.
Anyways, it's similar to what you are doing, but it's better encapsulated. You aren't passing 100 pieces of free floating information around, but rather passing a single object and building it up....assuming that's applicable to what you are doing.
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com... > First of all, thanks a lot for the sample code. > > Secondly, do you mean that it is not a good idea to create a session > object for each web control? > > I don't know if this is a good design or not, but my boss wants the > user-supplied data in web forms across multiple pages to be retained > while they jump around these pages. > > So, I think that session is the best solution. If looping through all > web controls is troublesome, I'll just do it the dumb way: create a > session line after another. > > > Karl Seguin wrote: >> I'm cautious about given any help 'cuz your approach seems mad! Why >> in >> the >> world would you ever want to do what you are doing?! We'll, I'll >> assume >> you've thought it trough *shrug*. >> >> public sub LoadIntoSession(byval parent as control, byref count as >> integer) >> for each child as Control in Parent.Controls >> count = count + 1 >> dim sessionKey as string = "Session" + count.ToString() >> dim value as string >> if typeof child is TextBox then >> value = ctype(child, TextBox).Text >> else if typeof child is ListControl then >> value = ctype(child, DropDownList).SelectedValue >> else if typeof child is ... ' youneed to do this for every type >> .. >> end if >> >> if child.HasControl then >> LoadIntoSession(child, count) >> end if >> next >> end sub >> >> >> Page_Load >> LoadIntoSession(Page, 0) >> end sub >> >> >> That code isn't perfect, but something like that should help... >> >> I still think it's probably a bad design...whatever you are doing.... >> Server.Transfer w/preserve Form might work, or using the >> HttpContext.... >> >> Karl >> >> -- >> MY ASP.Net tutorials >> http://www.openmymind.net/ >> <an***********@yahoo.com> wrote in message >> news:11**********************@o13g2000cwo.googlegr oups.com... >> >I want to create session objects for all web controls in a page. >> >Right >> > now, I am doing it in a dumb way like this (for example): >> > >> > Session("Session1") = ctrl1.Text >> > Session("Session2") = ctrl2.Text >> > Session("Session3") = ctrl3.Text >> > Session("Session4") = ctrl4.SelectedValue >> > Session("Session5") = ctrl5.Text >> > Session("Session6") = ctrl6.Text >> > >> > It would be good if I can get all web controls and loop through >> > them. >> > I searched this group and noticed that this topic has been discussed >> > in >> > a few threads. But I've tried >> > >> > For Each objCtrl in Page.FindControl("MyForm").Controls >> > >> > and >> > >> > For Each objCtrl In Page.Controls >> > >> > and >> > >> > For Each objCtrl In MyForm.Controls >> > >> > and >> > >> > For Each objCtrl In Me.Controls >> > >> > None of them worked. Would any guru please share your idea? >> > Thanks. >> > >
Hmm, that looks great. Looks like this way I am liberated from the
tedious session creation and retrieval task. I will definitely try to
test this. You might wanna put a tutorial about this on your web.
Karl Seguin wrote: Well, if you only need the data to exist while a user hits next> next> next> or <prev <prev <prev, you could do:
dim user as new User() .... Context.Items.Add("NewUser", user) Server.Transfer("Page2.aspx")
and then you can retrieve the user from Page2.aspx ala: dim user as User = ctype(Context.Items("NewUser", User") 'don't forget to check for nothing..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
Thanks a lot. Sounds like that is a much better way than session to achieve my goal. However, I still don't know anything about that yet.
Actually, a few days ago, I asked in this group if there is a better way than session, here:
http://groups.google.com/group/micro...56748848a2d36d
The MSDN link is helpful, but I cannot jumpstart from that brief doc. Could you point me to some more detailed documentation about how to implement this?
Thanks.
Karl Seguin wrote: Well, it's just going to lead to a cumbersome and complex design, in my opinion.
Either use Server.Transfer and PreserveForm (http://msdn.microsoft.com/library/de...sferTopic2.asp) which will maintain REquest.Form so atleast it's only 1/2 as hackish...or better yet...
create a business object and passthat in your session.
Say you are building a user registration thing with 3 pages, page 1 : basic information, page 2: address, page 3: membership details
Page 1 -->
sub btnPage2_Clicked dim user as new User() user.Name = UserName.Text user.Email= Email.Text user.Country= Country.SelectedValue Session("NewUser") = user Response.Redirect("Page2.aspx") end sub
Page 2 --> dim user as User = ctype(Session("NewUser"), User) if user is nothing then 'error, has to start on page 1 end if user.Telephone = telephone.TExt ... .. Response.Redirect("Page2.aspx") end sub
or you could just store the user in Context.ITems and use a Server.Transfer.
Anyways, it's similar to what you are doing, but it's better encapsulated. You aren't passing 100 pieces of free floating information around, but rather passing a single object and building it up....assuming that's applicable to what you are doing.
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com... > First of all, thanks a lot for the sample code. > > Secondly, do you mean that it is not a good idea to create a session > object for each web control? > > I don't know if this is a good design or not, but my boss wants the > user-supplied data in web forms across multiple pages to be retained > while they jump around these pages. > > So, I think that session is the best solution. If looping through all > web controls is troublesome, I'll just do it the dumb way: create a > session line after another. > > > Karl Seguin wrote: >> I'm cautious about given any help 'cuz your approach seems mad! Why >> in >> the >> world would you ever want to do what you are doing?! We'll, I'll >> assume >> you've thought it trough *shrug*. >> >> public sub LoadIntoSession(byval parent as control, byref count as >> integer) >> for each child as Control in Parent.Controls >> count = count + 1 >> dim sessionKey as string = "Session" + count.ToString() >> dim value as string >> if typeof child is TextBox then >> value = ctype(child, TextBox).Text >> else if typeof child is ListControl then >> value = ctype(child, DropDownList).SelectedValue >> else if typeof child is ... ' youneed to do this for every type >> .. >> end if >> >> if child.HasControl then >> LoadIntoSession(child, count) >> end if >> next >> end sub >> >> >> Page_Load >> LoadIntoSession(Page, 0) >> end sub >> >> >> That code isn't perfect, but something like that should help... >> >> I still think it's probably a bad design...whatever you are doing.... >> Server.Transfer w/preserve Form might work, or using the >> HttpContext.... >> >> Karl >> >> -- >> MY ASP.Net tutorials >> http://www.openmymind.net/ >> <an***********@yahoo.com> wrote in message >> news:11**********************@o13g2000cwo.googlegr oups.com... >> >I want to create session objects for all web controls in a page. >> >Right >> > now, I am doing it in a dumb way like this (for example): >> > >> > Session("Session1") = ctrl1.Text >> > Session("Session2") = ctrl2.Text >> > Session("Session3") = ctrl3.Text >> > Session("Session4") = ctrl4.SelectedValue >> > Session("Session5") = ctrl5.Text >> > Session("Session6") = ctrl6.Text >> > >> > It would be good if I can get all web controls and loop through >> > them. >> > I searched this group and noticed that this topic has been discussed >> > in >> > a few threads. But I've tried >> > >> > For Each objCtrl in Page.FindControl("MyForm").Controls >> > >> > and >> > >> > For Each objCtrl In Page.Controls >> > >> > and >> > >> > For Each objCtrl In MyForm.Controls >> > >> > and >> > >> > For Each objCtrl In Me.Controls >> > >> > None of them worked. Would any guru please share your idea? >> > Thanks. >> > >
Antony there is a clean example here at:- http://aspnet101.com/aspnet101/tutorials.aspx?id=20
Hope tha helps
Patrick
<an***********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... Hmm, that looks great. Looks like this way I am liberated from the tedious session creation and retrieval task. I will definitely try to test this. You might wanna put a tutorial about this on your web.
Karl Seguin wrote: Well, if you only need the data to exist while a user hits next> next>
next> or <prev <prev <prev, you could do:
dim user as new User() .... Context.Items.Add("NewUser", user) Server.Transfer("Page2.aspx")
and then you can retrieve the user from Page2.aspx ala: dim user as User = ctype(Context.Items("NewUser", User") 'don't forget to check for nothing..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
Thanks a lot. Sounds like that is a much better way than session to achieve my goal. However, I still don't know anything about that yet.
Actually, a few days ago, I asked in this group if there is a better way than session, here:
http://groups.google.com/group/micro...56748848a2d36d The MSDN link is helpful, but I cannot jumpstart from that brief doc. Could you point me to some more detailed documentation about how to implement this?
Thanks.
Karl Seguin wrote: > Well, it's just going to lead to a cumbersome and complex design, in
my> opinion. > > Either use Server.Transfer and PreserveForm >
(http://msdn.microsoft.com/library/de...-us/cpref/html
/frlrfSystemWebHttpServerUtilityClassTransferTopic2 .asp)> which will maintain REquest.Form so atleast it's only 1/2 as
hackish...or> better yet... > > create a business object and passthat in your session. > > Say you are building a user registration thing with 3 pages, page 1 : > basic > information, page 2: address, page 3: membership details > > Page 1 --> > > sub btnPage2_Clicked > dim user as new User() > user.Name = UserName.Text > user.Email= Email.Text > user.Country= Country.SelectedValue > Session("NewUser") = user > Response.Redirect("Page2.aspx") > end sub > > Page 2 --> > dim user as User = ctype(Session("NewUser"), User) > if user is nothing then > 'error, has to start on page 1 > end if > user.Telephone = telephone.TExt > ... > .. > Response.Redirect("Page2.aspx") > end sub > > or you could just store the user in Context.ITems and use a > Server.Transfer. > > Anyways, it's similar to what you are doing, but it's better > encapsulated. > You aren't passing 100 pieces of free floating information around,
but> rather passing a single object and building it up....assuming that's > applicable to what you are doing. > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ > <an***********@yahoo.com> wrote in message > news:11**********************@g47g2000cwa.googlegr oups.com... > > First of all, thanks a lot for the sample code. > > > > Secondly, do you mean that it is not a good idea to create a
session> > object for each web control? > > > > I don't know if this is a good design or not, but my boss wants the > > user-supplied data in web forms across multiple pages to be
retained> > while they jump around these pages. > > > > So, I think that session is the best solution. If looping through
all> > web controls is troublesome, I'll just do it the dumb way: create a > > session line after another. > > > > > > Karl Seguin wrote: > >> I'm cautious about given any help 'cuz your approach seems mad!
Why> >> in > >> the > >> world would you ever want to do what you are doing?! We'll, I'll > >> assume > >> you've thought it trough *shrug*. > >> > >> public sub LoadIntoSession(byval parent as control, byref count as > >> integer) > >> for each child as Control in Parent.Controls > >> count = count + 1 > >> dim sessionKey as string = "Session" + count.ToString() > >> dim value as string > >> if typeof child is TextBox then > >> value = ctype(child, TextBox).Text > >> else if typeof child is ListControl then > >> value = ctype(child, DropDownList).SelectedValue > >> else if typeof child is ... ' youneed to do this for every
type> >> .. > >> end if > >> > >> if child.HasControl then > >> LoadIntoSession(child, count) > >> end if > >> next > >> end sub > >> > >> > >> Page_Load > >> LoadIntoSession(Page, 0) > >> end sub > >> > >> > >> That code isn't perfect, but something like that should help... > >> > >> I still think it's probably a bad design...whatever you are
doing....> >> Server.Transfer w/preserve Form might work, or using the > >> HttpContext.... > >> > >> Karl > >> > >> -- > >> MY ASP.Net tutorials > >> http://www.openmymind.net/ > >> <an***********@yahoo.com> wrote in message > >> news:11**********************@o13g2000cwo.googlegr oups.com... > >> >I want to create session objects for all web controls in a page. > >> >Right > >> > now, I am doing it in a dumb way like this (for example): > >> > > >> > Session("Session1") = ctrl1.Text > >> > Session("Session2") = ctrl2.Text > >> > Session("Session3") = ctrl3.Text > >> > Session("Session4") = ctrl4.SelectedValue > >> > Session("Session5") = ctrl5.Text > >> > Session("Session6") = ctrl6.Text > >> > > >> > It would be good if I can get all web controls and loop through > >> > them. > >> > I searched this group and noticed that this topic has been
discussed> >> > in > >> > a few threads. But I've tried > >> > > >> > For Each objCtrl in Page.FindControl("MyForm").Controls > >> > > >> > and > >> > > >> > For Each objCtrl In Page.Controls > >> > > >> > and > >> > > >> > For Each objCtrl In MyForm.Controls > >> > > >> > and > >> > > >> > For Each objCtrl In Me.Controls > >> > > >> > None of them worked. Would any guru please share your idea? > >> > Thanks. > >> > > >
Hey, Patrick,
That is very helpful. I gave it a shot and it partially works, but
there is a slight problem which I don't know how to fix.
On page1.aspx, I have
Page1 | Page2 |
First Name:
Last Name:
Where Page1 and Page2 are LinkButton objects that point to the
respective pages. These two buttons also appear on page2.aspx.
On page2.aspx, I do get the info transferred from page1.aspx. But when
I hit the LinkButton Page1 to go back, the information is lost. And on
page1.aspx, I do have the following Sub:
Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
txtFirst.Text = Context.Items("first")
txtLast.Text = Context.Items("last")
End If
End Sub
Presumably, this sub should be able to retrieve the values from the
context and put them back to their respective textboxes.
Well, I know that the values will still be there if I hit the back
button of the browser. But that is not what I want.
Please let me know where I went wrong. Thanks a lot.
Patirck Ige wrote: Antony there is a clean example here at:- http://aspnet101.com/aspnet101/tutorials.aspx?id=20 Hope tha helps Patrick
<an***********@yahoo.com> wrote in message news:11**********************@g49g2000cwa.googlegr oups.com... Hmm, that looks great. Looks like this way I am liberated from the tedious session creation and retrieval task. I will definitely try to test this. You might wanna put a tutorial about this on your web.
Karl Seguin wrote: Well, if you only need the data to exist while a user hits next> next> next> or <prev <prev <prev, you could do:
dim user as new User() .... Context.Items.Add("NewUser", user) Server.Transfer("Page2.aspx")
and then you can retrieve the user from Page2.aspx ala: dim user as User = ctype(Context.Items("NewUser", User") 'don't forget to check for nothing..
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/ <an***********@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... > Hi, > > Thanks a lot. Sounds like that is a much better way than session to > achieve my goal. However, I still don't know anything about that yet. > > > Actually, a few days ago, I asked in this group if there is a better > way than session, here: > > http://groups.google.com/group/micro...56748848a2d36d > > The MSDN link is helpful, but I cannot jumpstart from that brief doc. > Could you point me to some more detailed documentation about how to > implement this? > > Thanks. > > Karl Seguin wrote: >> Well, it's just going to lead to a cumbersome and complex design, in my >> opinion. >> >> Either use Server.Transfer and PreserveForm >> (http://msdn.microsoft.com/library/de...-us/cpref/html /frlrfSystemWebHttpServerUtilityClassTransferTopic2 .asp) >> which will maintain REquest.Form so atleast it's only 1/2 as hackish...or >> better yet... >> >> create a business object and passthat in your session. >> >> Say you are building a user registration thing with 3 pages, page 1 : >> basic >> information, page 2: address, page 3: membership details >> >> Page 1 --> >> >> sub btnPage2_Clicked >> dim user as new User() >> user.Name = UserName.Text >> user.Email= Email.Text >> user.Country= Country.SelectedValue >> Session("NewUser") = user >> Response.Redirect("Page2.aspx") >> end sub >> >> Page 2 --> >> dim user as User = ctype(Session("NewUser"), User) >> if user is nothing then >> 'error, has to start on page 1 >> end if >> user.Telephone = telephone.TExt >> ... >> .. >> Response.Redirect("Page2.aspx") >> end sub >> >> or you could just store the user in Context.ITems and use a >> Server.Transfer. >> >> Anyways, it's similar to what you are doing, but it's better >> encapsulated. >> You aren't passing 100 pieces of free floating information around, but >> rather passing a single object and building it up....assuming that's >> applicable to what you are doing. >> >> Karl >> >> -- >> MY ASP.Net tutorials >> http://www.openmymind.net/ >> <an***********@yahoo.com> wrote in message >> news:11**********************@g47g2000cwa.googlegr oups.com... >> > First of all, thanks a lot for the sample code. >> > >> > Secondly, do you mean that it is not a good idea to create a session >> > object for each web control? >> > >> > I don't know if this is a good design or not, but my boss wants the >> > user-supplied data in web forms across multiple pages to be retained >> > while they jump around these pages. >> > >> > So, I think that session is the best solution. If looping through all >> > web controls is troublesome, I'll just do it the dumb way: create a >> > session line after another. >> > >> > >> > Karl Seguin wrote: >> >> I'm cautious about given any help 'cuz your approach seems mad! Why >> >> in >> >> the >> >> world would you ever want to do what you are doing?! We'll, I'll >> >> assume >> >> you've thought it trough *shrug*. >> >> >> >> public sub LoadIntoSession(byval parent as control, byref count as >> >> integer) >> >> for each child as Control in Parent.Controls >> >> count = count + 1 >> >> dim sessionKey as string = "Session" + count.ToString() >> >> dim value as string >> >> if typeof child is TextBox then >> >> value = ctype(child, TextBox).Text >> >> else if typeof child is ListControl then >> >> value = ctype(child, DropDownList).SelectedValue >> >> else if typeof child is ... ' youneed to do this for every type >> >> .. >> >> end if >> >> >> >> if child.HasControl then >> >> LoadIntoSession(child, count) >> >> end if >> >> next >> >> end sub >> >> >> >> >> >> Page_Load >> >> LoadIntoSession(Page, 0) >> >> end sub >> >> >> >> >> >> That code isn't perfect, but something like that should help... >> >> >> >> I still think it's probably a bad design...whatever you are doing.... >> >> Server.Transfer w/preserve Form might work, or using the >> >> HttpContext.... >> >> >> >> Karl >> >> >> >> -- >> >> MY ASP.Net tutorials >> >> http://www.openmymind.net/ >> >> <an***********@yahoo.com> wrote in message >> >> news:11**********************@o13g2000cwo.googlegr oups.com... >> >> >I want to create session objects for all web controls in a page. >> >> >Right >> >> > now, I am doing it in a dumb way like this (for example): >> >> > >> >> > Session("Session1") = ctrl1.Text >> >> > Session("Session2") = ctrl2.Text >> >> > Session("Session3") = ctrl3.Text >> >> > Session("Session4") = ctrl4.SelectedValue >> >> > Session("Session5") = ctrl5.Text >> >> > Session("Session6") = ctrl6.Text >> >> > >> >> > It would be good if I can get all web controls and loop through >> >> > them. >> >> > I searched this group and noticed that this topic has been discussed >> >> > in >> >> > a few threads. But I've tried >> >> > >> >> > For Each objCtrl in Page.FindControl("MyForm").Controls >> >> > >> >> > and >> >> > >> >> > For Each objCtrl In Page.Controls >> >> > >> >> > and >> >> > >> >> > For Each objCtrl In MyForm.Controls >> >> > >> >> > and >> >> > >> >> > For Each objCtrl In Me.Controls >> >> > >> >> > None of them worked. Would any guru please share your idea? >> >> > Thanks. >> >> > >> > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve Drake |
last post by:
All,
I have a CONTROL that contains 1 control (Control ONE), the 1 control that
it can contain 1 or 2 control (Control A and B).
Control A, raises and event and Control ONE receives this event...
|
by: Invalidlastname |
last post by:
Hi,
We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
|
by: Robert Howells |
last post by:
Perhaps I'm just too new at this to pull it off, or perhaps it's just bad
architecture. I'd appreciate some feedback on the the wisdom (or lack
thereof) in attempting the following:
I'm not new...
|
by: Sacha Korell |
last post by:
I'm trying to load a drop-down list with all DropDownList control names from
another page.
How would I be able to find those DropDownList controls? The FindControl
method will only find a...
|
by: Frank Esser |
last post by:
Hi,
I created an ASP.NET page (test.aspx) with some web controls in GridLayout
(Design time).
When I look at the collection page.controls by
foreach (Control ctrl in Page.Controls)
{
....
| |
by: Bass Pro |
last post by:
Hi,
I am creating textbox, radiobuttonlist and checkboxlist dynamically
depending on data from a table. It is a questionnaire.
I add the control on a Panel control during the 1st load_page event....
|
by: Nathan Sokalski |
last post by:
When I view any page in my application a second time, I recieve the
following error:
System.Web.TraceContext.AddNewControl(String id, String parentId, String
type, Int32 viewStateSize) +313...
|
by: Ankit Aneja |
last post by:
I have a strange situation and I have no idea how to solve this.
Its a Recruitment Search Page,in the Admin Page, for every button click
event the Admin Person has to create a checkbox on the users...
|
by: Mr Newbie |
last post by:
I was thinking about developing a workflow application yesterday and was
musing over the different approaches than one could take in restricting
specific actions on a ticket( Form ) at any said...
|
by: Bob Jones |
last post by:
I have an odd business requirement and I think that the implementation
is not correct in the terms of OOP development. Any help on the
concepts would be very appreciated!
We currently have a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |