Getting textbox value from one page to another page textbox value - asp.net

I am creating a form in my website and i link this form to the google docs (FORM which i created there). But this new form that i am trying to do is this in such a way that a textbox value from the first page should be passed over to the next page lets say page2 textbox value
CODE IS ROUGHLY SOMETHING LIKE THIS
PAGE 1.html,aspx,asp (Watever)
"/>
Page2.html,aspx,asp (Watever)
**readonly**"/>
So since i am using the google docs to save my data
**
form action="http://docs.google.com
i am unsure how to pass these values, tks for the help.
Presently i am just getting the values from page1 to page2 using this microsoft tutorial
http://support.microsoft.com/kb/300104

I think you need to read
How to: Pass Values Between ASP.NET Web Pages
you can store values using the approaches listed there.
Eg:
On your Page 1:
Create a textbox named textbox and an asp button.
on button.click code behind add
Session["test"] = textbox.Text;
Response.Redirect("Page2.aspx"); //Open page 2
On your Page 2 :
Creata a label named label1
Then on its Pageload Event in code behind
Add
string IpassAstringfrompage1 = Convert.ToString(Session["test"]);
label1.Text = IpassAstringfrompage1; //label1 will display TESTING from textbox on Page1
To test. On Page1 input "TESTING" on your textbox then click button
Regards

Related

How to Copy Content and Add New Record in Telerik Radgrid

Okay, basically I have a master page that only contains a RadGrid. I am using a custom popup WebUserControl form to handle the input for the update/insert controls. When I enter the edit mode I have a button called "Copy & Add New Record". When the user clicks on this button I want to copy 2/3 of the page content, open a new record, and then paste that information in the appropriate textboxes.
I have no problem copying or pasting the information. The problem lies with closing my current edit form and then opening a new record form. I tried closing the form using:
Dim temp As RadGrid = Parent.Page.FindControl("rgRT")
temp.MasterTableView.ClearEditItems()
temp.MasterTableView.IsItemInserted = True
And then setting the above statement to true to try to open the new record form. However it did not work. The popup edit form was still in the same position, I received no errors, and the only event to occur was an autopostback. I feel like this is something extremely easy but I cannot for the life of me figure it out.
Try adding a Rebind() call after clearing the insert items. This should put your grid in the defauilt (view mode) and remove the IsItemInserted = True call.
Try registering a script to init insert on the client so it goes into edit mode: http://www.telerik.com/forums/how-to-add-new-row-in-radgrid-clientside-which-should-be-inline-and-stay-in-editmode#hJ-0yiaxakaxzdOf-UXDYw (tip: you would want to use the Sys.Application.Load event for your code to execute, earlier calls may cause errors, something like below).
string script = "function f(){$find(\"" + RadGrid1.ClientID + "\").get_masterTableView().fireCommand("InitInsert", ""); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
then, use the ItemCommand event to set default values: Telerik RadGrid - How do I set default data on insert?

RadGrid hyperLinkColumn + retain values to new page

I have a radgrid populated when my page initially loads. I set a column in my radgrid as a hyperlink and was wondering how to retain the value of that particular column in the row clicked so when a new page is loaded I can use the value stored to perform an SQL query on the new page.
I am wondering if this is possible and how I would go about doing this?
Welcome to SO Jacob, I have done this before and it's not hard at all.
Example:
My select statement is "select top 5 ProductName from products"
I then created a hyperlink column and assigned the properties under the data section as seen in the screenshot below.
When run, it makes the data clickable and when clicked, it navigates to the url seen in the SS.
If you want to use it in a querystring change the DataNavigateUrlFormatString to:
http://google.com?ProductName={0}
You would then read it on your new page via:
var a = Request.QueryString["ProductName"]; //C#
dim a = Request.QuesryString("ProductName") 'Vb.net
If this is what you are after, click the green checkmark next to my answer to accept it and alert future users that this is the solution.

Ordering javascript code on a page executed with argument calculated in codebehind in ASP.NET

A situation requires me to order javascript code on a page be executed with an argument calculated in codebehind in ASP.NET
Here is the situation:
I have a page called search.aspx . This page contains a button and a textbox. Users put their arguments for search in the textbox and then click the button. The button posts back and runs a button click method. This code behind logic (running on the server) serializes and inserts the contents of the textbox to a DB.
Assuming a rowID or something to identify the serialized query by will be returned inside the button click method, how can I then tell the page (search.aspx) to open a new tab with results.aspx?query=.
I know I have to use javascript as the code behind can't open a new tab, but I am just wondering how to do so.
I've never used JS so a maximum amount of details in the answer is better.
Assuming your rowID is loaded in a variable named, well, rowID, then put this at the end of your click event (VB.Net):
ClientScript.RegisterStartupScript(me.GetType(), "results", _
string.Format("window.open('results.aspx?query={0}','Search Results','status=1')", rowID), True )
To directly answer your question, you can insert something like the following directly in the page output just before the body end tag.
<script type="text/javascript">
window.open("http://servername/pagename.aspx?queryid=blah");
</script>
by using Response.Write.
However, did you also consider simply opening a new window on the button click with the button's text passed in as a query string to an aspx page?

Adding a textbox dynamically

In my aspx page,when a user clicks on a Location "LinkButton", a new textbox should be dynamically added in the page.User can add a maximum of 10 textboxes.
Also, user can navigate to another page B from this page A.When he comes back to page A, all his textboxes should be persisted.
How do I achieve this functionality?
Thanks.
I would create a user control with a place holder object in it and then write something like:
if(NumberOfTextBoxes <= 10)
{
TextBox tb = new TextBox();
Placeholder1.Controls.Add(tb);
NumberOfTextBoxes++;
}
For reference I would recommend:
How to: Add Controls to an ASP.NET
Web Page Programmatically
PlaceHolder Class (The remarks section has a lot of HowTo's like the one above)
You need to keep information in the user's session about how many text boxes to show (and possibly their content). In the page's Init (?) handler you will need to add the text boxes each time.

How do I add a textbox dynamically in ASP.NET?

I've a following requirement for my asp.net page:
User can add a textbox dynamically on a page A by clicking on link "Add a new category" hyperlink
He clicks submit button on page A and gets redirected to page B.
When he clicks on page A link from this page, the textboxes that he added should be persisted.
Can someone help me with the code on this?
Appreciate your help!
In the ButtonClick Method write.
TextBox tb = new TextBox();
Parent.Controls.Add( tb );
The Parent is the control you want to add the textbox to, for instance a panel.
You can also look at this resource.
Hope it helps.
Adding a user control dynamically is simple. But in this case, I don't think you need to do that, instead you should look at creating a repeater with a textbox inside it, and when the user clicks Add Category, add one item to the repeater datasource.
This way you can handle both control creation and state persistence at the same time.
dealing with dynamic user controls can be a pain in the ass.
as a rule of thumb i follow, whenever you create a dynamic user control, then you must set it's ID so ASP.net can reallocate it on post back, and to keep the controls values after post back you should reload your user controls on Page_Init event.
hope this helps.
Dynamically creating Textboxes:
suppose you have page like this
when you enter '1' in textbox and click on ADD button,output will be like display one textbox
below..
i have designed like this,
i have one textbox and placeholder for displaying dynamic textboxes..
double click on Add button...in btnadd_click,you have to write the following code
protected void btnadd_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < Convert.ToInt32(txtno.Text); i++)
{
TextBox txtbox = new TextBox();
phtxt.Controls.Add(txtbox);
phtxt.Controls.Add(new LiteralControl("<br>"));
}
}
debug it... and the output is,
As others have stated adding the text box dynamically is fairly straight forward, just create the Textbox and add it to the controls collections wherever you need it to show up. You then need to store the information that this user gets this additional text box. Assuming that this is meant for long term, you will need to store this information in your backend store. Whenever you are constructing the page you will need to read the store information first to see what textboxes to create.
I would suggest doing it as follows. In the Onload event, if you have not done so before, load the dynamic information from your DB. Add any necessary controls to the page and store this information in viewstate. On any subsequent postbacks, read the information from viewstate to add the additional controls. This will save you from having to read constantly from the database on each postback.

Resources