Transferring Variables

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Oct 2008
Posts: 4
Reputation: planemaniac is an unknown quantity at this point 
Solved Threads: 0
planemaniac planemaniac is offline Offline
Newbie Poster

Transferring Variables

 
0
  #1
Oct 17th, 2008
Hi,

I have a really quick question. I have Sub Page_Load(...), and in that sub, I set a couple of variables. In a form, further down the page, in the <body> tag, I have a button, set so when I click it, it operates another Sub, Btn_Click(...). How can I access the variable I set in Page_Load in Btn_Click without using a URL transfer method?

Thanks

George
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Transferring Variables

 
0
  #2
Oct 17th, 2008
just create your fields after your class declaration before any event handlers, then you can reach them from everywhere in your codefile
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 4
Reputation: planemaniac is an unknown quantity at this point 
Solved Threads: 0
planemaniac planemaniac is offline Offline
Newbie Poster

Re: Transferring Variables

 
0
  #3
Oct 18th, 2008
I don't know what you mean by Class Declaration, but what I have is:

  1. <html><head><script language="VB" runat="server">
  2. Sub Page_Load(s As Object, e As EventArgs)
  3. Dim DayNum As Integer
  4. DayNum = 3
  5.  
  6. End Sub
  7.  
  8. Sub Btn_Click(s As Object, e As EventArgs)
  9.  
  10. Response.Write(DayNum)
  11.  
  12. End Sub
  13. </script>
  14. </head><body>
  15. ... HTML ... </body>
  16. </html>

How can I transfer that variable DayNum from the Sub Page_Load to the Sub Btn_Click?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Transferring Variables

 
0
  #4
Oct 18th, 2008
why dont you use code behind files? are you migrating from classical asp or php?
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 4
Reputation: planemaniac is an unknown quantity at this point 
Solved Threads: 0
planemaniac planemaniac is offline Offline
Newbie Poster

Re: Transferring Variables

 
0
  #5
Oct 18th, 2008
Yes, I'm migrating from PHP. Is there anyway I can do this without using Code Behind files, or will I have to?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Transferring Variables

 
0
  #6
Oct 18th, 2008
yes you can do it without codebehind files but after a while you will confront them everywhere so that will be inevitable. asp.net is organized in code behind manner so just use them.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: n4naeem is an unknown quantity at this point 
Solved Threads: 1
n4naeem n4naeem is offline Offline
Newbie Poster

Re: Transferring Variables

 
0
  #7
Oct 21st, 2008
Sub Page_Load(s As Object, e As EventArgs)
Dim DayNum As Integer
DayNum = 3
Session["DayNum"] = DayNum;

End Sub

Sub Btn_Click(s As Object, e As EventArgs)

Response.Write(System.Convert.ToInt32(Session["DayNum"]));

Session["DayNum"] = null;

End Sub


Originally Posted by serkansendur View Post
yes you can do it without codebehind files but after a while you will confront them everywhere so that will be inevitable. asp.net is organized in code behind manner so just use them.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC