943,960 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 818
  • ASP.NET RSS
Oct 17th, 2008
0

Transferring Variables

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
planemaniac is offline Offline
4 posts
since Oct 2008
Oct 17th, 2008
0

Re: Transferring Variables

just create your fields after your class declaration before any event handlers, then you can reach them from everywhere in your codefile
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Oct 18th, 2008
0

Re: Transferring Variables

I don't know what you mean by Class Declaration, but what I have is:

ASP.NET Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
planemaniac is offline Offline
4 posts
since Oct 2008
Oct 18th, 2008
0

Re: Transferring Variables

why dont you use code behind files? are you migrating from classical asp or php?
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Oct 18th, 2008
0

Re: Transferring Variables

Yes, I'm migrating from PHP. Is there anyway I can do this without using Code Behind files, or will I have to?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
planemaniac is offline Offline
4 posts
since Oct 2008
Oct 18th, 2008
0

Re: Transferring Variables

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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Oct 21st, 2008
0

Re: Transferring Variables

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


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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
n4naeem is offline Offline
8 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: error in database connection
Next Thread in ASP.NET Forum Timeline: reading a text file to a remote PC





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC