Updating a textbox before the form is submitted

Hi all,

 I am writing a control extender for textboxes. When the user submits the form (may be partial or a full post back) I want to check the textbox text property (value property in JavaScript) and update it.

I added a handler to Application object's unload event using Sys.Application.add_unload() method. My handler did fire when the page got unloaded, but it happens after the data is submitted, so any update I do on the textbox is irrelevant because the data was submitted already.

Is there any other method I can use in order to achieve the ability to evaluate the textbox's text and do something with it before the data is sent?

I thought about attaching to the form's onSubmit event, but I am pretty sure it will not work when validators are in the page. Their validation method stops the onSubmit handlers chain, right?

Thank you for your time,

David. 


To Infinity and Beyond!
0
davidtravis
6/21/2007 10:26:56 PM
asp.net.ajax-ui 9760 articles. 0 followers. Follow

6 Replies
380 Views

Similar Articles

[PageSpeed] 9

 Hi David,

       I read your problem, but still not perfectly clear about what you are trying to do.  [ When the user submits the form (may be partial or a full post back) I want to check the textbox text property (value property in JavaScript) and update it.], I want to be clear on this line.

From whatever I've understood..... 

 Do you want to check the the textbox's value and and do some manipulation before the data is submitted? You can call a javascript on  "OnTextChanged" event and check it at the time the user is entering the text.

 

And since you have posted it here in AJAX forum, how are you using AJAX here?

can you give more detail of your problem.

 



 


-------------------------------------------
Thanks,
Mehul Mistry


If you feel your question is answered then please click "Mark As Answer" to the post that answered it. Thanks :-)
0
mehulmistry
6/22/2007 6:21:36 AM

Hi,

I am posting this message here be cause the forum's description states that it relates among other stuff to client API. My post is about control extenders which rely on Sys.UI.Behavior, which is a part of this API, isn't it? :-)

You understood exactly what I want to do. I want to manipulate (if required) the textbox's text (in javascript) right before the form's submission, so the new value it has will be reflected in server side events in this postback.

I don't want to use onChange event because this means the manipulation will take place when the control loses focus. I want to manipulate it right before the forms submits.

Thank you for your reply,

David. 


To Infinity and Beyond!
0
davidtravis
6/22/2007 6:57:40 AM

HI David,

    Are you having any button in your form which is submitting your form. If so, you can try the following....

1. Add your javascript function you want to manipulate in the aspx file.

2. In the code behind, add the javascript function call to the button on click event as Button2.Attributes.Add("onClick", "myJavaScriptFunction();")   in the page load event.Alternative you can do the same thing by adding the javascript function name to the Button's OnClientClick event. In this the javascript function is called first and you can manipulate the content of the textbox and in the code behind you will be able to get the modified value of the textbox.

 

eg: <script  type="text/javascript">

     function myJavaScriptFunction() {
                    document.getElementById("TextBox1").value = "from javascript" ;
                    } 

  </script>


For your button you can do <asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="myJavaScriptFunction() "  />   or in the page load in the code behind you add Button2.Attributes.Add("onClick", "test();").

Hope this might help. Also if any other control (apart from button) in your form is causing a postback the to that control also you do the above thing and it should solve the prob.

 

 


-------------------------------------------
Thanks,
Mehul Mistry


If you feel your question is answered then please click "Mark As Answer" to the post that answered it. Thanks :-)
0
mehulmistry
6/22/2007 8:25:32 AM

 Hi Mehul,

First thanks for the thorough reply!

I am not sure this is a good solution for me, the hook should come from the extender and not from the button. This for several reasons:

  1. This is an extender, the whole idea is that you don't need to edit anything in the page. Adding the extender and setting only the extender's properties is the right method.
  2. Since an extender is a pluggable component no one can "promise" me that everytime this extender is used there will be a button in the page as well.

There is another important issue - validators. They are hooked to the Form's OnSubmit event. So if I hook my extender to the same event it may not be fired (the validation handler has a "return" in the end, so the handlers chain is interrupted).

Do you happen to know if there is a way to hook to an event like OnBeforeValidation or something like this?

I was sure this is a simple challenge,  now I am not that sure of it...

Thanks again,
David.


To Infinity and Beyond!
0
davidtravis
6/22/2007 9:43:55 AM

Hi All,

Problem solved.

I don't know how I missed it, but the solution is pretty simple (as I thought it should be...):

this._form = $get('form1');
if (this._form != null) {
            this._submitHandler = Function.createDelegate(this, this._onSubmit);
            $addHandler(this._form, 'submit', this._submitHandler);
}

in this._onSubmit I evaluate the textbox value and manipulate it if required. I checked it with validators as well and it is working just fine.

I want to thank Damian Meher for opening my eyes!

Good Day,
David.


To Infinity and Beyond!
0
davidtravis
6/22/2007 7:30:40 PM

Thanks davidtravis Smile


Chetan Sarode
Software Engineer,
Approva Systems Pvt Ltd,
Pune, India.
0
chetan
6/23/2007 3:59:52 AM
Reply:

Similar Artilces:

form.submit() not submitting form.
 I have an aspx that contains an ascx. The ascx is a list of files that the user can click on to open. The code around this looks like:         private void openAttachedFile(string fileName)        {            string appPath = ConfigurationManager.AppSettings["AttachmentPath"].ToString() + @"\" + fileName;            FileStream fs = File.OpenRead(appPath);     ...

Form inside AJAX update panel isn't submitting line breaks correctly with Firefox and Safari
 Hi,I have some strange behaviour with my form inside an update panel when using Firefox and Safari, but not with IE7 (works fine in IE). I will try and describe what is happening below:I have a FormView inside an update panel inside a repeater. When i change the FormView to edit mode, and update text in my textbox (also with inserting text), the text that is inserted isn't adding in the linebreaks i input. If i set EnablePartialRendering="False"  for the page it works correctly. This makes me think it's an error with AJAX and the update panel. I have checked the ...

textbox outside ajax update panel doesnt get updated
 Hi All.I have an update panel on my form, inside that panel i have some stuff. The trigger for this update panel is a button which is outside the panel. Outside the panel i also have a textbox, upon clicking the button, there is a line that goes .Text=string.empty. However, the textbox does not get set to empty. I then put the textbox in another update panel and set the trigger to the button too. It worked. but is there any other way around this? Or is this ok? Hi, that is fine. There is no other way as the update trigger must be inside the update panel with the controls you wish t...

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...

Submitting form with AJAX
I'm trying to figure out how to submit a form with AJAX so that a postback does not occur.  I would like to set up everything in ASP.NET such that I can utilize ClientScriptManager, ScriptManager, and the UpdatePanel.  Help is greatly appreciated! Thanks! Just put the form inside an UpdatePanel.--Moayad MardiniMSDN Forums ModeratorRemember to mark the helpful replies as answers! It's not giving me the results I want.  I still have to force a refresh on the page to get the updated page.  Is there a way to call a server side function from the client using a...

Urg Help: My Form View Item Update Event wont update the textboxes..
Hi All I have been trying really hard to get my last page working. I am using: DropDown List inside the template to get new values, Formview EditItem Template and SQL DataSource and Microsoft Access to create database.. Its a simple form where I need to update all textboxes and checkboxes when changing the selection from dropdown list and DDL contains project number. AutoPostBack =True and AppendDataBoundItems is = true  Here is  my code in vb: Private Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs) 'Dim ProjectNameTextBox A...

Submitting Web forms fields to sql database by clicking on SUBMIT FORM and sending the form fields to email box
I have a created or designed a form to be stored in a SQL database table and at the same time when a user clicks on SUBMIT button the form fields will automatically goto the visitor email address immediately. Also i have created a database with tables for each of this forms Pls help i have over 10 forms designed but the problem of submitting them to the table database and the user email address is the challenge now.... You ned to familiarise yourself with the basics of database access in ASP.NET.  There are free tutuorials here: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/da...

Ajax.Form and JQuery.submit
I can't seem to get the two to play together nicely (preview 5).  Basically I have a Ajax.Form that contains a text box (for a date field) [no submit button].  When I enter a date and press enter - it correctly uses Ajax to retrieve my partial view and displays it.  However, when I hook up the JQuery UI DatePicker to the field and set it's 'OnSelect' to do a submit (thus automatically submitting the form when a date is chosen from the UI) - the Ajax submit seems to be ignored fully (it acts like a normal form submit) and I get a whole new document showing my pa...

Dropdownlist submit ajax form
I am trying to use an ajax form that when submitted changes some text in a span tag. The code works perfectly when I add a submit button, but when I put an onchange="submit();" into the dropdownlist the returned string replaces the entire page and is not placed into the span tag. Here is the relevant part of the view, the controller has a method called GetVarieties that returns a string. <%using (Ajax.Form("GetVarieties", new { }, new AjaxOptions { UpdateTargetId = "varietyDD", }, new { id = "ajaxForm" })) { Response.Write(Html.DropD...

Pop up form in ajax with textboxes
On a form (with ajax) in a popup window there are plain textboxes for simple text entry. What is the easiest way to enforce text be filled in the textboxes before user click OK to close the form?Please mark the post(s) that have helped you as "Answer" hi!   how about the old RequiredFieldValidator ?   ciao ;-)jan maruClick "Mark as Answer" on the post if my words were helpful. Please kindly answer this: http://forums.asp.net/t/1242382.aspx Thanks.Please mark the post(s) that have helped you as "Answer"...

Updateing from ATLAS to AJAX.NET?
Hey!I have built a stie that uses a early version of ATLAS where a webservice was created and then by using java i could do callbacks and let the java change my page.Now i want to update to AJAX.NET and AJAX control toolkit.I have followed the fallowing steps:Download AJAX.NET Beta 1 and Ajax control toolkit.Executed the AJAX.NET setup where i choosed removeExecuted the AJAX.NET setup and choosed installUnpacked and executed the Ajax control toolkitRemoved the references in my projectFollowed the steps in the AJAX.NET migration doc witch involved some web.config editing and moved the scriptm...

clearing textboxes when submitting a form
  What would be the best (least code and fastest to run) method of doing this.  I have read that doing a redirect to the same page would be useful. I also want to send the user an message on screen that states that the form was submitted, then clear the textboxes, I know how to do this by setting the string of each text box to "", but this seems like a lot of code when you have 13-20 textboxes. There has to be a more elegant way. TIA, Chris You can do it in a loop. It depends on how far down the container tree you are, but here is an example if all your textboxes are o...

non .net form issue within a .net form tag
this may be a bad question... but I am adding a shopping cart to my asp.net website and it calls for the following code for the 'buy now' buttons: <form method="POST" action=http://www.cart.net/cart.aspx/CartName><input type="hidden" name="ID" value="IDName"><input type="hidden" name="Describe" value="IDName Description"><input type="hidden" name="Price" value="100.00"><input type="hidden" name="QtyMax" value="1"><input t...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Web resources about - Updating a textbox before the form is submitted - asp.net.ajax-ui

Scholastic - Another kid-submitted question: How do I get... - Facebook
Another kid-submitted question: How do I get a reader to feel the creepy things I write? Well, by having it all seen and heard and smelled by ...

Update: Facebook for iPhone 3.0 Submitted to Apple (& New Screenshots)
As we wrote yesterday, Facebook for iPhone 3.0, which will include a spate of new features like Page updating, video uploading, events, likes, ...


Key Coalition policies not submitted for independent costings
The Coalition has not submitted its climate change, broadband and asylum seeker policies for independent costing ahead of Thursday's final release ...

$4B Kitimat LNG project submitted for environmental review
A $4-billion plan for a pipeline and liquefied natural gas export terminal by Shell Canada Ltd. for Kitimat, B.C., has been submitted to federal ...

Revised UNESCO bid submitted for boreal forest along Manitoba-Ontario border
Manitoba is trying once again to get special UNESCO recognition for the boreal forest the province shares with Ontario.

Syria chemical weapons plan submitted
Syria chemical weapons plan submitted

Members of 12th CPPCC discuss proposals to be submitted
Members of 12th CPPCC discuss proposals to be submitted People's Daily Online Peng Zhao (C), Li Bin (R) and Long Qian, members of the 12th ...

Apple Maps team reportedly contacting business owners to verify user-submitted address corrections
... AAPL Company and maps at 9to5Mac . What do you think? Discuss "Apple Maps team reportedly contacting business owners to verify user-submitted ...

New version of LGBT discrimination measure submitted to Anchorage Assembly
After criticism from all sides, a new proposal has been put forward to change or eliminate some of the religious exemptions to the law that Bill ...

Resources last updated: 12/28/2015 5:10:54 PM