Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, April 2, 2008 5:55 AM
HI to all,
i want to pass the values from one page to another
Thanx,
sudha
All replies (21)
Wednesday, April 2, 2008 6:28 AM ✅Answered
i want to pass the values from one page to another
There are numerous ways to do this and it all boils down to the requirement as each has its own pros and cons
You can use
Session, query strings, cookies, form post data
Wednesday, April 2, 2008 10:29 AM ✅Answered
Check below link
Ways to pass data between webforms
HC
Friday, April 4, 2008 4:52 AM ✅Answered
hi
let us suppose in first.aspx page one button,textbox are there.
when u click on button u want to redirect to second.aspx page and also u have to pass the value of textbox in first.aspx to second.aspx.
if u want to do the same u can do it by querystring
in Button_click()
{
Response.Redirect("second.aspx?name='"+textBox1.Text+"' ");
}
now u want retrive the value in second.aspx page
in page_load() {
string str=Request.QueryString["name"].ToString();
}
thanks
with
regards
sekhar
Wednesday, April 2, 2008 6:33 AM
I vote for the query string [:P]
Wednesday, April 2, 2008 7:11 AM
Actually my requirement is i have main page(having one textbox) and second page,now i am going to second page from first page when i am clicking the up arrow key now in second page shows some data in datagrid now i select the single row using select linkbutton then this row value(means single cell) will be back to first page
i think you are understand my problem
thanx,
sudha
Wednesday, April 2, 2008 8:19 AM
just use the code like this,
Response.Redirect("yourpage.aspx?id=SelectedCellValue")
'in the second page you can get the qury string value like this
Dim strValue As String
strValue = Request.QueryString("SelectedCellValue").ToString()
Wednesday, April 2, 2008 9:31 AM
Hi Sudha,
For this you might need to do this way.
<asp:datagrid...>
...
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<a href="FirstPage.aspx?ID=<%# Container.DataItem("ID") %>">some Text</a>
<ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
hope this helps!
-Purushotam (http://purusworld.blogspot.com)
Thursday, April 3, 2008 1:17 AM
HI Thirumaran,
Where Should i write Query string means in which event i have to write Querystring, if i am writing in page load(first page) then i am getting the error
that was
"Object reference not set to an instance of an object. "
txtbusinesslocation.Text= Request.QueryString["x"].ToString();
Please tell me which event i hav to write and any conditions.
Thanx,
sudha
Friday, April 4, 2008 5:39 AM
Well.. When you Redirect to any page using Server side script like Resonse.Redirect("somepage.aspx?id=" + someid.ToString()) that means its a Get action which means, one can query id using Request.QueryString() method. Before you get any querystring, check for any querystring avaialbe from the redirected url using Reqeust.QueryString.HasKeys() and then get key/value from it, otherwise your query will fail.
Another case is, When you submit a Page by clicking Submit button, then the action is Post, in such case on server side, you can query from Request.Form[] collection.
Now, in your case, I would guess you are using Redirect method of Response and obviously you should be able to query using QueryString() collection.
Another thing i noticed is do not apply ToString() when you expect casting from QueryString[], use Convert.ToString() instead. Since Convert.ToString() helper handles nulls!
If you are not still clear, send me your code, so that i can be able to narrow the solution.
hope this helps!
-Purushotam (http://purusworld.blogspot.com)
Wednesday, April 9, 2008 12:51 AM
HI purushotam,
I got the result , i know how to use querystring (from firstpage to second pageload),but my scenario is firstpage to second page then first page,so if i write querystring in first page load then run application i will get error,now it will be ok with out using query string i got the result
THANX FOR ALL
thanx,
sudha.
Wednesday, April 9, 2008 5:16 AM
Hi,
I undestood your problem. what you would need is, implement the logic as shown below:
FirstPage.aspx
<body>
<form id="form1" runat="server">
<div>
Category: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
</div>
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
FistPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
string category = Convert.ToString(Request.QueryString["Category"]);
this.Label1.Text = "You have posted " + category + "from Second Page";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/SecondPage.aspx?Category=" + TextBox1.Text);
}
SecondPage.aspx
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
Send this to First Page again:
<asp:Button ID="Button1" runat="server" Text="Send to First Page"
onclick="Button1_Click" />
</div>
</form>
</body>
SecondPage.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
string category = Convert.ToString(Request.QueryString["Category"]);
this.Label1.Text = category;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/FirstPage.aspx?Category=" + Label1.Text);
}
with this logic, your scenario should work... or buzz me if you are not clear
-Purushotam (http://purusworld.blogspot.com)
Friday, April 11, 2008 1:23 AM
hai sir,i want to do a search in my real estate web site.i have to print all the images and details in the databse in a form sucha way that for form 8 controls and rest has to come in other pages.i need to do custom paging.i am not using datagrid.now you have explained how to pass the values from one page to another page .so sir i want to create a page and send a parameter from actual search page to here to get each image using that id.so pls help to store images in database and do property search.
krishna
Friday, April 11, 2008 5:06 AM
basically i'd say dont store images to database, just store the filenames in an 1:n table.
well you'll just add a simple " select .. from thing t join thing_image i on i.id=t.imageid where t.id = " + QueryString["id"] in your sql string? (better using parameters)
please tell me if i misunderstood
Sunday, April 13, 2008 11:44 AM
thank you sir.
but i didn't understand what u mean.if u explain clearly it will be more useful for me.
thank you sir.
Sunday, April 13, 2008 1:58 PM
create table realty {
id int primary key,
......
.....
}
create table realtyimage {
realtyid int foreign key references realty,
filename varchar(255),
}
store the filenames into realtyimage with realtyid of the realty the image belongs to.
sorry if that didnt help maybe you could explain more about your problem
Friday, August 22, 2008 3:22 AM
Hi All,
I would like to know how to pass value in a textbox of one webform to a datagrid in another form. Can anyone help me with it...
Thanks
bluee
Friday, August 22, 2008 4:13 AM
WOW that will really help him.. i reported him.
first go to the textchanged event of the textbox.
then make a decision: sessions or querystring.
i use sessions. so in the textchanged event type:
Session["parameter"] = txtYourTextBox.Text; response.redirect("othersite.aspx");
in the othersite.aspx (page load event):
if(!IsPostBack) {
// set the value to the gridview here, like:
string strParameter = Session["parameter"] as string;
}
with querystrings you drop the Session["parameter"] = ... and use response.redirect("othersite.aspx?parameter=" + txtYourTextBox.Text); instead
in the othersite.aspx, page load event:
if(!IsPostBack) {
string strParameter = Request.QueryString["parameter"];
}
i hope that helps
Friday, August 22, 2008 7:30 AM
thanks for the reply..
but how do i make it appear in the datagrid..
thanks,
bluee
Friday, August 22, 2008 7:44 AM
sorry but isnt datagrid an .net form application control, i only know about a gridview, datalist and repeater in asp.net 2.0?
do you mean a gridview? do you use asp.net 2.0?
if its a gridview, it would be
GridView1.Rows[0].Cells[0].Text = Session["Parameter"];
Friday, August 22, 2008 8:11 AM
thank you..
sorry i was wrong... i actually meant a gridview.. thanks anyways
bluee
Friday, August 22, 2008 8:19 AM
no problem, glad i could help!