How do I keep the value for a textbox in the textbox when the form resets for the next insertion using Details View?

I'm using Details View to insert data to the database. First up one form is visible to enter product details. When that save to the database I get the new primary key using "SELECT MAX(ProductID) FROM Product" (probably not the best way but it works so long as no one else is inserting data at the same time). The first form is hidden and the next form is shown. The primary key is inserted into the ProductID text box and the details for the new items for the product are entered and then saved to the database. All good. BUT when the insert button is clicked on the second form and it reloads to allow for further items to be entered it loses the ProductID.

How do I keep the value for that textbox in the textbox when the form resets for the next entry?

Cheers

Sally

I'm using vb - and am very new to it.

0
thehappyferal
9/21/2008 10:48:58 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

5 Replies
904 Views

Similar Articles

[PageSpeed] 28

"The primary key is inserted into the ProductID text box "

 

How are you carrying over the value from the first form to the second form?


AllAboutFocus.com.
Information Technology Solutions
Helping You Focus. Helping You Succeed.
0
patrick24601
9/22/2008 3:56:50 AM

 I'm guessing you're inserting the ProductID into the textbox only on initial page load (ie !IsPostBack). Whatever procedure you run that inserts the ProductID into the textbox, make sure that on every page load, whether postback or not, that this same procedure is called.

So, if you have:

if (!IsPostBack) {
 // procedure call, maybe
  TextBox1.Text = ProductID;
  // other first-time initialization code here
}

you should have it as:

if (!IsPostBack) {
  // other first-time initialization code here
}

// always run
TextBox1.Text = ProductID;

0
ed_ajax_guy
9/22/2008 4:10:32 AM

0
thehappyferal
9/22/2008 4:24:32 AM

This is the code I'm using. I've also tried adding it to the Insert button on click event but it won't re-enter it. I'm not sure if I've lost its value or it just won't re-enter it.

    Protected Sub ProductDetailsForm_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles ProductDetailsForm.ItemInserted

Dim NewID As Integer

Dim
connectionString As String = ConfigurationManager.ConnectionStrings("SystemConnectionString").ConnectionString

Using myConnection As New Data.SqlClient.SqlConnection(connectionString)
myConnection.Open()
Dim FindID As String = "SELECT MAX(ProductID) FROM Product"
Dim myCommandID As New Data.SqlClient.SqlCommand(FindID, myConnection)
NewID = myCommandID.ExecuteScalar()
myConnection.Close()

End Using

Dim ProductID As TextBox = CType(ItemDetailsForm.FindControl("ProductIDTextBox"), TextBox)

ProductID.Text = NewID

End Sub
 

 I've no idea about postback - well vb at all really

Cheers

Sally

0
thehappyferal
9/22/2008 4:25:17 AM

thehappyferal:

This is the code I'm using. I've also tried adding it to the Insert button on click event but it won't re-enter it. I'm not sure if I've lost its value or it just won't re-enter it.

Hi thehappyferal,

The code above is totally correct I think and can you tell me in details that when the ProductID gets lost?

I suppose the ID is displayed in the ProductID TextBox when the second form shows up, right? So, did you mean it gets lost when it is inserted into database?

By the way, is ProductDetailsForm the second form's ID?  

Anyway, would you please show me your code on inserting the data into database? Well, the complete codes will be better.

Best Regards,
Shengqing Yang


Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
0
Shengqing
9/26/2008 4:18:38 AM
Reply:

Similar Artilces:

C#.NET WEB APPLICATION
hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

Inserting default value in form view Textbox
In ASP 2.0 In the form view control (set to insert mode)  how would I set a default value in one of the text boxes in the control.  (umTextBox is the ID)   Thanks for any help! Try searching the forum for "formview default value" for past discussions:http://forums.asp.net/search/SearchResults.aspx?q=formview+default+value+sectionid%3a24&o=Relevance...

Reseting Textboxes in a Web Form using C#
How do I reset several textboxes on a webform using C#. I have the following protected void ResetButton_Click(object sender, EventArgs e) {   } How do I bind the textboxes to the click event? Thanks, Janis TextBox1.Text = String.Empty TextBox2.Text = String.EmptyThanks, EdMicrosoft MVP - ASP/ASP.NET Thanks so much, should I use the same format to clear a calendar field as well? I haven't used the Calendar control very much so I'm not too sure what a calendar field is. However, most controls have their own way of resetting themselves. Therefore, any two controls may...

How to change the value of a TextBox inside a Web Form in Insert mode?
Hi, If the textbox txtDate is outside a Web Form, we can change the values as follow: txtName.Text = "James"; If the item is inside a Web Form in Insert mode, how can I change the TextBox value by using .net script or JavaScript at run-time?  Thanks, James Hi James,If I understand your question, you want to be able to change the value using JavaScript within the browser, not the code-behind.  You would do that with something like this:<script language="javascript" type="text/javascript">document.getElementById(<%=txtName.ClientID.ToStr...

HTML textboxes appear but not web form textboxes
Hi all, I'm new to all this VS.net and I tested it by creating a new project, and clicking and dragging an asp textbox onto the aspx page. Upon clicking "Build and Browse" the asp textbox does not appear at all. So I double checked, and yeah, Visible was set to true. So I tried clicking and dragging a normal textbox and strangely, the html textbox does appear on the screen. Please help on how I can make the ASP textbox appear. I constructed a webform entirely of ASP textboxes and ASP buttons and nothing on the page appears. Is there anything I need to add/remove on the con...

[Inserting data from form]How to change value of TextBox before inserting it into database by FormParameter?
 How to change value of TextBox before inserting it into database by FormParameter? Here is test script. I would like to create script which add "ok" to value of TextBox with ID="name_pl" and then insert it to database using FromParameter. For example, when I write "let" in TextBox and click "Submit", script insert to database "letok". How to do this? I have tried to do this by adding name_pl = name_pl + "ok"; before links.Insert(); but this cause error "CS0029: Cannot implicitly convert type 'string' to '...

Hi...passing textbox value one form to another form...
how  to pass the one form textbox value to another form datagrid  (pop-up window Datagrid) ...Jani... Hi, refer my article http://www.aspsnippets.com/post/PopUps.aspxMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets  To pass data from one form to another form you can use the following:1. TextBox txtName  = (TextBox)Page.PreviousPage.FindControl("textboxid");     textboxid is the id of the TextBox  that is generated at runtime you can find it in  page source of the previous page(Pag...

Convert Web.UI.WebControls.TextBox to Windows.Forms.TextBox
 I am trying to take user selected text from a textbox and save that portion to a string value, but the only method I have found involves using the System.Windows.Forms namespace and since I am using the FindControl method to pull the text box control from a form view, it throws a "can not convert webcontrol to form" error at me.  So far I have been able to bring the form view controls into the code behind page, but I still have the problem of grabbing the selected text.  Here is my code:         Dim textBox As System.Web.UI.WebCont...

can someone one give me difference between web form and mobile web form and which or where or when i'm using the forms?
thanks Marc Hi Marc, Based on my understanding, you want to know the differences between the ASP.NET web application and ASP.NET mobile web application. If I have misunderstood you, please feel free to let me know. The ASP.NET forms are used to develop the ASP.NET pages for desktop browsers and The ASP.NET mobile forms are used to develop the ASP.NET pages for mobile device browsers. When we create the ASP.NET mobile web forms pages, we can use nearly all the features of ASP.NET. But there are a couple of compatibility issues: Error Handling and Reporting. Tracing. Using Redi...

Passing value from details view to other web form
Hi, I am using the Grid view and for details I am using the details view. Now my situation is that I need to paas the value to other web form. So how can I pass the value from details view to other web form. you can either use query string or store the value into session and retieve it on the other pageSriPlease mark as answer if it helped you Hey, I am using the querystring, but how can I do that. Here is my query string, inthe details view. <SelectParameters> <asp:QueryStringParameter Name="JobID_I" QueryStringField="ID" Type="Int64" />...

How to retrieve textbox value using request.form ??????
 Hi i want to retrieve data of a textbox present in one webform from another webform.I am using server.transfer() for that. But request.form["TextBox1"] is not giving nullAlso i have used a loop to pass through entire collection. Bi did not get textbox there. So what's wrong and where ???????/ thanx in advance    Try the PreviousPage property: protected void Page_Load(object sender, EventArgs e) { if (PreviousPage != null) { TextBox pTextBox = (TextBox)PreviousPage.FindControl("TextBox1"); ...

Assign TextBox Value From 1 Form to Another Form on another page
I have searched for days without finding the answer that Im looking for. I have created a marketing request form table called tblRequestForm with a few basic fields. [RequestFormID] , [FormTitle] , [Department] , [YourName]. I also have created another table called tblRequests that has these fields. [RequestID] , [RequestFormID] , [RequestTitle] , [RequestDescription]. I am trying to fill out the RequestForm on page1.aspx then on insert, postback the [RequestFormID] automatically into FormRequest on page2.  I am really new to this and help would be great.~Mickey...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

referencing textboxes on web forms using code behind
 Hello: On my web form I have several text boxes named from textbox1 to textbox30. How do I "reference" these text boxes in code behind "vb.net"? Say i wish to write a for loop. for i = 1 to 30 textbox[i].text.length>0 stmt... next i How do I code this part? You can get idea from following link http://forums.asp.net/p/1148526/1866897.aspx-SuganRemember to click “Mark as Answer” on the post If you get answer from this post(s) ! Try the FindControl method.For i = 1 To 30 Dim txt As...

Web resources about - How do I keep the value for a textbox in the textbox when the form resets for the next insertion using Details View? - asp.net.web-forms

Insertion loss - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Insertion at Sunrise - Flickr - Photo Sharing!
Marines with Bravo Company, 1st Battalion, 7th Marine Regiment, insert into Tagvreshk Village by CH-53E Super Stallion helicopters during a mission ...

Samsung Galaxy Note 5 now features a warning about backwards S Pen insertion
Not too long after Samsung's Galaxy Note 5 was released to the masses, many consumers began trying to insert the S Pen in their devices the wrong ...

Microsoft updates OneNote for iOS and Mac with OneDrive access, file insertion, more
Microsoft on Tuesday rolled out a major update to its Apple-centric OneNote product line, adding new features like access to notes stored in ...

Optomeditech Helps Solve Catheter Insertion & Grabs $2.5 Million From Lifeline And Sitra
... is as high as 30%. That means injury, extra costs for equipment, lost time. All of which matters a lot in healthcare. “Every catheter insertion ...

Steam vulnerability can lead to remote insertion of malicious code
Aurich Lawson Millions of Steam users are potentially vulnerable to a newly disclosed attack method that exploits a hole in the way Steam commands ...

eBay Sees E-Commerce Growth Slowing In ’08; To Unveil Plans To Cut Insertion Fees, Raise Final Value ...
The economy, you will not be shocked to learn, can affect eBay. In an interview this afternoon with Tech Trader Daily, eBay CFO Bob Swan says ...

Why Understanding the Value of Dynamic Ad Insertion is so Important to Content Owners and Broadcasters ...
Dynamic Ad Insertion (DAI) is a concept that has been discussed in the cable TV industry for years. The reason is simpleDAI has the potential ...

Toshiba Unveils SOI Process Achieving the Lowest-class Insertion Loss in the Industry for RF Switches ...
... for RF switch applications in smartphones that achieve TarfSOI front-end process optimized for RF switches, achieves the lowest-class insertion ...

Democrats Booed Re-Insertion of God, Affirmation of Israel's Capital in Platform
-By Warner Todd Huston Earlier in the day on Wednesday, the Democrat Party suffered two embarrassments over its platform by the elimination both ...

Resources last updated: 11/25/2015 5:23:28 PM