Unable to get the updated text of text box - html

I've one text box and one update button:
Text box:
<asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
update button:
<asp:Button ID="btnUpdFName" runat="server"Text="Update" onclick="btnUpdFName_Click"/>
What I am doing in page load event I am getting the first name from database and assinging it to text box as follows:
txtFName.Text = dt.Rows[0][1].ToString();
Now when i earases the text set at page load event in text box as above and write another name and press update button, i am trying to get the new text entered in the text box in the button click event as follows:
string FName = txtFName.Text;
But the problem is that every time I write new text in text box, I am still getting the same text as set form database (dt.Rows[0][1].ToString()).
I am not able to get the current text from the text box and getting only the intial value set from db in page load event.
What I encountered that after compilation my text box markup becomes as follows:
<input id="CPHcontent_txtFName" type="text" value="value set from db i.e. dt.Rows[0] [1].ToString()" name="ctl00$CPHcontent$txttxtFName"></input>
the text box alway has the same value set from the db. Thats why i am getting each time the same value regardless of value entered by user in text box.
Now tell me how to get the updated value of text box in my page behind.
Thanx in advance

In asp.net webforms you should separate code for setting data to control and for saving data to db. One of ways to set data to control - use check
if (!IsPostBack)
{
txtFName.Text = dt.Rows[0][1].ToString();
}
in page load event.
Otherwise you will overwrite your newly entered text for textbox on every page load.

You are probably overwriting the text you entered in your Page Load event, because you are not checking if it is a PostBack.
Please read ASP.NET Page Life Cycle Overview for further information.

Set the textbox to empty or null before you try to set/read it again onpageload.

Related

How to show the saved text in text field

In my HTML page, there is a button new and a button modify, when I click the button new, a new page will show with an empty single line text field, the code of the text field is:
<input type="text" name="functionInfo.paramsText"/>
so I can input some text in the text field and save it into the database (the data will be put to Java and saved into a database), this is exactly what I want, but when I click modify to modify a text which has been stored in the database, the new page is shown with an empty text field, how can I get a text field with the stored text shown on it? So I can see what I have saved before.
If you use Struts tags then it's simply
<s:textfield name="functionInfo.paramsText"/>
The value will be set via evaluating OGNL expression in the name attribute. You only need to provide a bean functionInfo with property paramsText and getters for both.
If you put a bean to the action class, then using a getter it's accessible from the value stack via OGNL since the action bean is on top of the value stack.

How can I make a text box that when filled out and hit enter, checks a box by the code that was typed in?

How can I make a text box that when filled out and hit enter, checks a box by the code that was typed in?
There are multiple fields in each row in the database; Accountability check box, Name, ID number, address, , etc... Respectively. I want to have a split form that has fields to edit view each profile and then a table with all the data on the bottom. I want to have a box that when the ID number is typed into will check the box for accountability, and then I want to have a button that will uncheck all of the accountability check boxes to reset it.
I will make ID cards with bar codes and a scanner that will be set up to hit "enter" after the code, so I want it to run continuously.
I am very used to Excel and VBA but I have never used Access, So I am trying to get a start on it.
Thank you for any help and if you have any recommendations on how to make this simpler or better I would appreciate it!
Thanks in advance!
If the text box name is txtTextBox and check box chkCheckBox, then use After Update event of txtTextBox with code like:
chkCheckBox = False
If Len(NZ(txtTextBox)) > 0 Then chkCheckBox = True

Is there any way to override a mailto field with another field?

AKA, if I have two fields (one radio button group and one textarea that only appears if the "other" radio button is pressed) how would I make it so the input from the text area overrides the "other" button having it's value placed in the mailto?
E.g., I want this to happen:
field1=text from text area
NOT this:
field1=other
field2=text from text area
Could I set the value of the "other" radio button in field1 to the text coming from the text area?
Alternatively, could I do anything to prevent a certain field from appearing in the mailto fields?
In future, please ensure you present SO with a code issue, not a general question or request. However, you would use a JQuery change handler, like so:
$('#mastertextboxid').on('input', function(){ //executes every time master's text is updated
$('#slavetextboxid').value($('#mastertextboxid').text()); //updates the values
})
This will overwrite any text in the slave textbox when the master textbox is changed, but the User will still be able to input into the slave textbox. It's known as One way data binding.

Input Field with text already populated on page load

I have a custom Visual Force page that on load has a name field that is supposed to have {Auto} printed inside the input text box that the user can delete or leave or not. I have been using a html-placeholder however the text just disappears and is gray.
My VF inputfield:
<apex:inputfield required="true"
value="{!EventPackageRevenueBreakdown__c.Name}" html-placeholder="{!Auto}"></apex:inputfield>
What it looks like with that code:
What I need it to look like (notice the cursor is after the closing scope)
Thanks in advance I'm still very new to this!
I suggest you to set Name field in controller with '{Auto}' value.
The placeholder attribute will disappear when there is a value in the field, what you want is to actually set the VALUE of the field to {Auto}.
Try this:
If you want it to automatically clear the field if a user clicks into it, you could add some javascript to handle that.

copy value entered in unbound textbox to label after pressing button

I have an unbound text box on my form which the admin can enter a date of when records were last updated. I want this date to be copied to a label after pushing a button so that it holds the date instead of it do disappear after closing the form.
does anyone know if this is possible and how it is possible?
For creating a variable that can be used AFTER the form is closed:
Create a new module (in code window, click 'Insert | Module'
Insert the variable name(s) and types you want available everywhere. i.e.
Global dtLastUpdated As Date
Global strSaveSomeName As String
Save the module as mdl_Globals
Add code wherever needed to set the variable, then can reference anywhere.
If for use during the form, use the following: where 'lblForUnbound' is the Label field and 'txtUnbound' is your unbound text box
Me.lblForUnbound.Caption = Me.txtUnbound.Text