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.

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.

you can do that using javascript too :
use an html textbox and html button instead of server controls :
<input type="text" id="textbox1" />
<input type="button" id="button1" value="myButton" onclick="document.location= 'mySecondPageUrl?param=' + document.getElementById('textbox1').value />

in your second page you can get the value using Request objects QueryString property.

void secondPage_Load(object sender, EventArgs e)
{
int i = Convert.ToInt32(Request.QueryString["param"]);
}

Then you can do whatever you want with that number.

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.