Enabling button after text changed on text box from form view control

I'm using form view to display some text box that contains user's personal info. There are "save" buttons for each text box which are disable as default.

I want to enable them when text is changed on the the text box. I don't know how to write the the JavaScript function to do this task and i also don't know how to call the function from the the textbox control (onchange or ontextchange?).

Here is the formview code:

<asp:FormView ID="FormView1" runat="server" DataSourceID ="personalSQL">

<ItemTemplate >

<table class="personalTable">

<tr>

<td class ="personalLabel">™ ”˜ˆ‰:</td>

<td class ="personalBox">

<asp:TextBox ID="textBoxFN" runat="server" Text ='<%# Eval("shippingFirstName") %>' ></asp:TextBox>

</td>

<td>

<asp:Button ID="buttonFN" runat="server" Text="™Ž…˜" Enabled ="false" />

</td>

</tr>

 

thanks.

 

0
sagreen
10/9/2008 10:25:13 PM
asp.net.client-side 24353 articles. 2 followers. Follow

10 Replies
1430 Views

Similar Articles

[PageSpeed] 45

 1) firstly, set autopostback true at textbox

<asp:TextBox ID="textBoxFN" runat="server" Text ='<%# Eval("shippingFirstName") %>'  AutoPostBack ="True"></asp:TextBox>

 2) secondly, enable the button in your codes

Protected Sub textBoxFN_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles textBoxFN.TextChanged

   if len(textBoxFN.text) > 0 then  buttonFN.enabled = True

End Sub

Cheers, Grussen!

 


gregale.NET, implico.de

0
Gregale
10/10/2008 9:26:04 AM

Thanks, but i want to do it on the client side.

0
sagreen
10/10/2008 9:31:01 AM

 Try this:

protected void FormView1_DataBound(object sender, EventArgs e)
        {
            FormView f = (FormView)sender;
            TextBox t = f.Row.FindControl(tid) as TextBox;
Button b = f.Row.FindControl(bid) as Button;
t.Attributes["onchange"] = "enableButton(" + b.ClientId + ")";
        }

 

Add following javascript:

function enableButtton(id)
{
var e = document.getElementById(id);
if(e.disable) e.disabe = false;
}

0
Macolele
10/10/2008 10:05:18 AM

 here we go! try this...

<script type="text/javascript">
        function apply()
        {
                   document.form1.Submit1.disabled=false     
        }
    </script> 

<input id="Text1" type="text" onkeydown ="apply()"/>
<input id="Submit1" type="submit" value="submit" disabled="disabled" />

 


gregale.NET, implico.de

0
Gregale
10/10/2008 11:02:54 AM

Thanks for your answers but it still doesn't work.

I think the problem is on calling the javascript function when the text changed. I added alert("blabla") to the javascript function but it didn't appear on the screen when i changed the text on the textbox.

Mayby i don't know where to write the javascript on the page.

I'm using  master page and i have placed the javascript on the head content like this:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script language ="javascript">

function enableButtton(id)
{
var e = document.getElementById(id);
if(e.disable) e.disabe = false;
}

</script>

</asp:Content>

0
sagreen
10/10/2008 2:33:19 PM

I believe that the only way to do that would be to attach the event handler in the CodeBehind. Here's an example:

aspx file:

<form id="form1" runat="server">
    <asp:FormView ID="budgetFormView" runat="server" AllowPaging="True" OnPageIndexChanging="budgetFormView_PageIndexChanging" Width="70px">
  <itemtemplate>  
   <asp:TextBox ID="formViewTextBox" Text='<%# Eval("ItemText") %>' runat="server"></asp:TextBox>
  </itemtemplate>
    </asp:FormView>
 <asp:Button ID="saveButton" Text='Save' runat="server"></asp:Button>
</form>

<script type="text/javascript">
<!--
function textBoxOnChange(elementRef)
{
 document.getElementById('<%= Button1.ClientID %>').disabled = false;;
}
// -->
</script>

aspx.cs file:

protected void Page_Load(object sender, EventArgs e)
{
 if ( !this.IsPostBack )
 {
  this.budgetFormView.DataSource = this.CreateDataSource();
  this.budgetFormView.DataBind();
 }

 saveButton.Attributes.Add("disabled", "true");
 TextBox textBoxRef = (TextBox)(budgetFormView.FindControl("formViewTextBox"));

 textBoxRef.Attributes.Add("onchange", "textBoxOnChange(this);");
}
protected void budgetFormView_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
 budgetFormView.PageIndex = e.NewPageIndex;

 this.budgetFormView.DataSource = this.CreateDataSource();
 this.budgetFormView.DataBind();

 TextBox textBoxRef = (TextBox)(budgetFormView.FindControl("formViewTextBox"));
 textBoxRef.Attributes.Add("onchange", "textBoxOnChange(this);");
}

NC...

0
NC01
10/10/2008 3:36:32 PM

Change event will fire only after lost focus from the testbox client side, Here it is there in "onKeyDown" event.

Try this...


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
   
   <script language="javascript" type="text/javascript">
        function disableButton()
        {
            myButton="<%=Button1.ClientID %>";
            alert(myButton);
            if (document.getElementById)
            {
                // this is the way the standards work
                document.getElementById(myButton).disabled = true;
            }
            else if (document.all)
            {
                // this is the way old msie versions work
                document.all[myButton].disabled = true;
            }
            else if (document.layers)
            {
                // this is the way nn4 works
                document.layers[myButton].disabled = true;
            }
        }
    </script>
    
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:TextBox ID="TextBox1" runat="server" onKeyDown="disableButton();" ></asp:TextBox>
     
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>

 


saAction

Please Don't forget to click "Mark as Answer" on the post that helped you.
0
saAction
10/10/2008 4:10:49 PM

sagreen:

Thanks for your answers but it still doesn't work.

I think the problem is on calling the javascript function when the text changed. I added alert("blabla") to the javascript function but it didn't appear on the screen when i changed the text on the textbox.

Mayby i don't know where to write the javascript on the page.

I'm using  master page and i have placed the javascript on the head content like this:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script language ="javascript">

function enableButtton(id)
{
var e = document.getElementById(id);
if(e.disable) e.disabe = false;
}

</script>

</asp:Content>


Sorry I didn't test my code. It should be:

function enableButton(id) {
                var e = document.getElementById(id);               
                if(e.disabled) e.disabled = false;
}

Use onkeydown if you want button enable immediately.

This was tested:

 

protected void FormView1_DataBound(object sender, EventArgs e)
        {
            FormView f = sender as FormView;
            Button b = (Button)f.Row.FindControl("Button1");
            TextBox t = (TextBox)f.Row.FindControl("TextBox1");
            t.Attributes["onkeydown"] = "alert('')";
            //t.Attributes["onkeydown"] = "enableButton('" + b.ClientID + "')";
        }
 
0
Macolele
10/10/2008 5:11:13 PM

 javascripts should be placed in masterpage's head section. have you tried my codes. it's really work.

cheers!


gregale.NET, implico.de

0
Gregale
10/13/2008 1:05:51 AM

Gregale.net:

javascripts should be placed in masterpage's head section. have you tried my codes. it's really work.

cheers!

Except that he said that the elements are in a FormView so your code will not work since then the button will not be named "Submit1" it will be something like "FormView1_buttonFN".

NC...

0
NC01
10/13/2008 4:05:34 PM
Reply:

Similar Artilces:

control text in a text box inside a Form view
I want to get text from a querystring into a text box that is prt of a form view. I have tried writing code in the page load that changes the text value inside that text box but i get the error that the texbox name is not in the current context. My question is how to call a textbox (or any other control) inside a form view? You can use the FormView's OnDataBound event to access the textbox on your formview: OnDataBound="FormView1_OnDataBound" Protected Sub FormView1_OnDataBound(ByVal sender As Object, ByVal e As EventArgs)        If FormView1.Curren...

problem in moving the focus of one text box to another text box inside a grid view on clicking a button
i have text boxes and buttons under template field inside item template of a grid view.on clicking the button updation in data base takes place based on the text box value.i want to move the focus of the text box to the next text box when updation of the first row inside the grid is complete.my grid  view is under an update pannel.i am getting the text box controls like  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)    {            TextBox txtUrlName = (TextBox)GridView1.Rows[Conv...

The performance in big form with about 70 controls(60 text box, 15 buttons, 5 combo box)
I have a big form with about 50 textbox or 5 combo box  and 15 command buttons, when I choose one item from a combo box, it need to get data from database and populate info. every time I click combo box it will refresh form and it's  very annoying.  Is it anyway to improve  performance? thanks  alot. I heard of AJAX, Does anybody have experience on it ? thanks. Summer06 AJAX may help you out with that. You can see home pretty cool examples and download the Atlas CTP from here. We've done some proof of concept work and it works really well for a scenario simi...

changing the text on text box
hello, i need to build an addon which takes (on mouse click) the text of any given input text box and change it. how do i get theobject of the text box and set my text to its value. thanks... ...

how to add text to control (ex. text box) after page sent to the client
Hi,, I have program that uses multiple threads to send files , I want to inform the user with the current processes done . if any thread has sent the file a text box in the web form must show this statement "file XYZ has been sent ". the problem is i need to update the tex box text, how could that  be done at the end of the thread work without any action from the user You'd need to use AJAX.-Tab Alleman Yes, you would need ajax.you can download ajax for free on http://www.asp.net/ajax/downloads/ once ajax is enable, that would definitely solve your...

Ritch Text Box control from Free Text Box
I have a client that is complaintaning about how hurd it is to format a html page with that tool it is great for someone like us who knows how to work with HTML and all that.. is it a good program or tool that i can show him so he ca format a page for easily ?? right now is using Word and do a copy paste..but its not showing off the same thing... thanx.I like programming If he is using word you might want to look at this... Peters MHTML Control Cheers, Dave...

i need to have a page with text box and button on... people will put email in text box and press button....
then i need to check that email against database entries and if it matches an entry i need to go to another page if not then a different one.. Can anyone help. please. i use VB. not sure how far you are on this so I'll start at the beginning...  not sure where you need the detail so i'l start out high level..  1.  create stored procedure in database accepting string (email) and returning integer (select count(*) from whatevertable where whatevercolumn=@email) 2.  create function to call procedure passing in email: private function DoesEmailExist(txtEmail) as ...

How do I block a user from entering text in a text box if they type text in another text box?
I have two text boxes, and want the user to complete one or the other.  How can I "grey out" one text box if a user starts typing in the other textbox?  Never make important decisions on a Monday! You can use the OnTextChanged event of the textboxes and write Javascript for both textboxes to disable the other textbox when the user starts to type in something in one textbox. The only problem with that is that once the user starts to type in something in one text box the other textbox gets disabled and locks up, so now the user HAS TO compulsarily type what he wants in th...

get the changed value of a text box
Hello everybody! I have this in the server side: <asp:textbox id="TEscala" runat="server"></asp:textbox> <asp:imagebutton id="BIrEscala" runtat="server" imageurl="images/irmapa.gif"> </asp:imagebutton> And i want to do this: Private Sub BIrEscala_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BIrEscala.Click Dim xx As String xx = Tescala.value End Sub The problem is that "xx" doesn´t get the new value written in the ...

Check if the text box "text" has changed (RePost from web forms forum)
Greetings! How can i know if the "text" inside of a text box has changed? For example, I currently have this: if (txtMU.TextChanged()) { } But this does not work. The other idea I had was to assign the existing value of the text box to a string and then when the user click the save button I can create a conditional statement to compare the original string with the new string. However, I would like something more effective as I have like 12 text boxes to compare. Thanks, EduardoThanks,Please Mark this post as answered if it was helpful. Here is the easiest way that I have ...

Passing Text of a text box in child form to a label in parent form
Hi Elite People !! I have a parent form with a number of ASP Labels and Buttons. Each ASP Label has a ASP Button next to it. What I want to acheive is when you click the button, it should open a new window with a ASP multiline text box and a "save" button. User can enter the text in the text box and when they click the SAve button, the Text in the text box of the Child window should be displayed in the label on the parent form.  I am successfully able to do this when I have a Text Box in the Parent form, but my requirement is to use Labels on the Parent Form. I am ...

Changing the text of an input (text) control
Hi everyone, please answer the following: I have a html input control as follows  <input id="newSearch_keywords" type="text" class="text" value="<%=JobsSearchBusinessObject.CurrentKeywords %>" name="newSearch_keywords""/>    When the page loads I need to look at the text of this input field and remove any * chars that are in the text. Thanks for your help <input id="newSearch_keywords" type="text" class="text" value="<%=JobsSearchBusinessObject.CurrentKeywords.Re...

Text box
I have a Popup calendar that opens when i click on the parent form and, and after selecting date - it fills the parent textbox and closes the popup window. Every thing is working fine, but i have one problem, i want the Textbox - textchanged event to fire when there is a change,(auto postback for textbox is set to true). This is not happening. If i manually type in the date in the textbox and go to other control then it fires, but not when i select date from PopUp. How to make it work Appreciate any response. Thanks. Parent Form JAVASCRIPT function OpenCalendar(...

changing text in static text control
Hello PB 11 build 8123 I have a window with a dwcontrol. When I am updating the dw control I want one of the column names (static text controls) to change based on a value I select in another column. So far I have the code in the itemchanged to capture the value of my selection in the field I first select. How do I take this value, (it can only be Y or N) and program one of the column headings (static text) to display a certain text? I can't seem to get it to work with setitem or settext. Those two funcs don't really work with column headings as far as I can see. A...