| | |
Passing a variable to another page
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
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.
Thanks for any help or ideas.
•
•
Join Date: Feb 2008
Posts: 43
Reputation:
Solved Threads: 2
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.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 121
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.
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.
Last edited by serkan sendur; Feb 16th, 2008 at 1:17 pm.
Due to lack of freedom of speech, i no longer post on this website.
Just put it in Session or QueryString.
In first page set on button click event:
Then in second page use something like this:
In first page set on button click event:
ASP.NET Syntax (Toggle Plain Text)
Session("Number") = Me.MyTextbox.Text.Trim --or-- Response.Redirect("Secondmenu.aspx?Number=" & Me.MyTextbox.Text.Trim)
Then in second page use something like this:
ASP.NET Syntax (Toggle Plain Text)
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
Last edited by ManicCW; Feb 18th, 2008 at 4:06 am.
•
•
Join Date: Feb 2008
Posts: 30
Reputation:
Solved Threads: 4
•
•
•
•
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.
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
![]() |
Similar Threads
- Passing variable value from javascript to jsp page at run time (JSP)
- server problems? passing variable info... (ASP)
- Calling .cfm page from ASP.NET (ColdFusion)
- login page (PHP)
- help on passing variable to a function? (JavaScript / DHTML / AJAX)
- Passing a LINK as a session variable (PHP)
- passing parameters to a page (JavaScript / DHTML / AJAX)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: How to register page for a web user control codebehind??
- Next Thread: [B]DropDownList, TextBox to GridView.....[/B]
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 ajax alltypeofvideos appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit editing embeddingactivexcontrol feedback fileuploader fill findcontrol flash folder form gridview gudi iis image javascript list listbox login maps microsoft mobile mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols parent problem project radio redirect registration relationaldatabases reportemail richtextbox rows schoolproject search security select sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview validatedate validation vb.net videos vista visualstudio vs2008 web webapplications webdevelopment webprogramming webservice wizard xsl






