954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Passing a variable to another page

I need help getting a variable from one page displayed onto another. I have two pages, mainmenu.aspx and secondmenu.aspx. mainmenu.aspx contains Textbox1 which contains some user-entered number in it. When the user clicks on Button1 on mainmenu.aspx, I need the table, Table1, on secondmenu.aspx to reflect that new selection.

Thanks for any help or ideas.

Dano56
Newbie Poster
1 post since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

First off- what language are you using vb.net or c#? You should verify the user entry is a # if that's what is expected... then convert it to a number vb = CInt/Int3.Parse(varNumber) then "post" this page to your 2nd page secondmemu.aspx - then do a request.form() for the textfield posted from the old field, then update your table once you get the value.

bbqchickenrobot
Light Poster
43 posts since Feb 2008
Reputation Points: 9
Solved Threads: 3
 

you can do that using javascript too :
use an html textbox and html button instead of server controls :

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Just put it in Session or QueryString.
In first page set on button click event:

Session("Number") = Me.MyTextbox.Text.Trim
--or--
Response.Redirect("Secondmenu.aspx?Number=" & Me.MyTextbox.Text.Trim)


Then in second page use something like this:

Dim myFilter as Int16
Try
myFilter = CInt(Session("Number"))
--or--
myFilter = CInt(Request.QueryString("Number))
Catch ex As Exception
--code for error handling--
End Try
ManicCW
Junior Poster in Training
95 posts since Nov 2005
Reputation Points: 13
Solved Threads: 11
 

I need help getting a variable from one page displayed onto another. I have two pages, mainmenu.aspx and secondmenu.aspx. mainmenu.aspx contains Textbox1 which contains some user-entered number in it. When the user clicks on Button1 on mainmenu.aspx, I need the table, Table1, on secondmenu.aspx to reflect that new selection.

Thanks for any help or ideas.

hi Dano56,
I think answer for your query is QueryString OR Session. But according to me prefer querystring so, i given following example as follows.
For ex. You want to go from Page1 on click event of button it redirects you at Page2 then pass query string along with Page2's URL. Suppoese your query string name is "qstr" then on click of button following steps should occur.
Button_click
{
Response.Redirect(Page2.aspx?qstr=id);
}
Then 1) on the load event of page2 check for query string
2) update your page base on querystring

To get the value of the query string on the page2 load event as follows

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["qstr"] != null)
{
string qstr1 = Request.QueryString["qstr"].ToString (); // statement for accessing querystring from aspx.cs file
}
}


To get the value of the query string from any class as follows

System.Web.HttpContext.Current.Request.QueryString["id"].ToString (); //statement for accessing querystring from any .cs file

Hope this will help you.
Thanks & Regards
Dilip Kumar Vishwakarma
Programmer .Net Consulting

dilipv
Light Poster
30 posts since Feb 2008
Reputation Points: 10
Solved Threads: 4
 

You should only use session variables for information related to the session... but of course, this will work...

bbqchickenrobot
Light Poster
43 posts since Feb 2008
Reputation Points: 9
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You