473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formatting: Focus in textarea: enter to submit form with serverside event trapping

Hi,

I have a problem with formatting a table including text fields wich can
contain up to 255 chars.

I need a table with 3 columns:
- First column 50 % over the with a rowspan of the total number of rows.
- Second column 25 %, no rowspan
- Third column 25 %, no rowspan

In the first column / cell contains a description. The next column a
caption, and the last column a edit field.

See http://www.winit.nl/sample/1.html
This shows the right layout (Using IE 6). If a text fields has the focus,
pressing enter will submit the form.

But when the text in the fields is to big, the layout is wrong (but still,
enter = submit)
See http://www.winit.nl/sample/2.html

To solve this problem, I replaced the input type=text with a textarea with
style overflow=hidden.
Only the enter key now gives a newline instead of a submit
See http://www.winit.nl/sample/3.html

The prevent newlines in the textarea i can use some client side scripting.
See http://www.winit.nl/sample/4.html

But how to submit the form using enter, and still be able to use the event
trapping of the submit button in the aspx page?
(Or how to use a input type = text resulting in the right layout)?

Perry
Nov 19 '05 #1
10 2996
Hey,

Instead of submit button put a button on the page and invoke form submit if
your layout is matched. You can still retain your textbox.
(e.g)
<input type=button onclick="test();">

<script>
function test()
{
if (condition)
document.form1.submit();
}
</script>
Hope this would solve your issue. Let me know if you need any other
clarification.

-Baskar BV-

"Perry van Kuppeveld" wrote:
Hi,

I have a problem with formatting a table including text fields wich can
contain up to 255 chars.

I need a table with 3 columns:
- First column 50 % over the with a rowspan of the total number of rows.
- Second column 25 %, no rowspan
- Third column 25 %, no rowspan

In the first column / cell contains a description. The next column a
caption, and the last column a edit field.

See http://www.winit.nl/sample/1.html
This shows the right layout (Using IE 6). If a text fields has the focus,
pressing enter will submit the form.

But when the text in the fields is to big, the layout is wrong (but still,
enter = submit)
See http://www.winit.nl/sample/2.html

To solve this problem, I replaced the input type=text with a textarea with
style overflow=hidden.
Only the enter key now gives a newline instead of a submit
See http://www.winit.nl/sample/3.html

The prevent newlines in the textarea i can use some client side scripting.
See http://www.winit.nl/sample/4.html

But how to submit the form using enter, and still be able to use the event
trapping of the submit button in the aspx page?
(Or how to use a input type = text resulting in the right layout)?

Perry

Nov 19 '05 #2
If i use a document.form1.submit(); i don't get the server side click event
in the aspx file. I need this event on the server.
Nov 19 '05 #3
To get around that, create a button that submits to the server (input
type=button runat=server id=btn)
And in the JavaScript submit that button btn.Submit(), which will trigger
its Post Back as well

HTH

"Perry van Kuppeveld" <no*****************@spam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
If i use a document.form1.submit(); i don't get the server side click
event in the aspx file. I need this event on the server.

Nov 19 '05 #4
I didnot get your question. Can you share the code which u have written?

-Baskar BV-

"Perry van Kuppeveld" wrote:
If i use a document.form1.submit(); i don't get the server side click event
in the aspx file. I need this event on the server.

Nov 19 '05 #5
I created a new C# webapp and placed the following code in webform class (In
design mode nothing is changed)
See the dif between pressing enter while the focus is in the textbox, or
clicking the submit button.

Code:
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
TextBox tb = new TextBox( );
tb.TextMode = TextBoxMode.MultiLine;
tb.Attributes["onkeypress"] = "if (event.keyCode == 13) {
document.forms[0].submit(); return false; }";
this.FindControl("form1").Controls.Add(tb);

Button b = new Button();
b.Text = "Submit";
b.Click +=new EventHandler(b_Click);
this.FindControl("form1").Controls.Add(b);
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

private void b_Click(object sender, EventArgs e)
{
Response.Write("Submit");
}
}
Nov 19 '05 #6
Hey,

try the code given below.
<script>
function test()
{
document.form1.button1.click();
}
</script>
<form method="post" name="form1" onsubmit="test();" runat=server>
<input type=text>
<input type=button onclick="button_click" runat=server>
</form>
the code will invoke client "test" function which then invokes button1 click
event. So if the user submits the form by pressing enter you could check for
the format validation and submit or not accordingly.

"Perry" wrote:
I created a new C# webapp and placed the following code in webform class (In
design mode nothing is changed)
See the dif between pressing enter while the focus is in the textbox, or
clicking the submit button.

Code:
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
TextBox tb = new TextBox( );
tb.TextMode = TextBoxMode.MultiLine;
tb.Attributes["onkeypress"] = "if (event.keyCode == 13) {
document.forms[0].submit(); return false; }";
this.FindControl("form1").Controls.Add(tb);

Button b = new Button();
b.Text = "Submit";
b.Click +=new EventHandler(b_Click);
this.FindControl("form1").Controls.Add(b);
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

private void b_Click(object sender, EventArgs e)
{
Response.Write("Submit");
}
}

Nov 19 '05 #7
I don't think this will work:

If i click the button script button_click will be executed, and that is not
available.

I will post a new question with the code provided in the previous post, so
it's back on the top.

Thanks anyway
"BASKAR BV" <BA******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hey,

try the code given below.
<script>
function test()
{
document.form1.button1.click();
}
</script>
<form method="post" name="form1" onsubmit="test();" runat=server>
<input type=text>
<input type=button onclick="button_click" runat=server>
</form>
the code will invoke client "test" function which then invokes button1
click
event. So if the user submits the form by pressing enter you could check
for
the format validation and submit or not accordingly.

"Perry" wrote:
I created a new C# webapp and placed the following code in webform class
(In
design mode nothing is changed)
See the dif between pressing enter while the focus is in the textbox, or
clicking the submit button.

Code:
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
TextBox tb = new TextBox( );
tb.TextMode = TextBoxMode.MultiLine;
tb.Attributes["onkeypress"] = "if (event.keyCode == 13) {
document.forms[0].submit(); return false; }";
this.FindControl("form1").Controls.Add(tb);

Button b = new Button();
b.Text = "Submit";
b.Click +=new EventHandler(b_Click);
this.FindControl("form1").Controls.Add(b);
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

private void b_Click(object sender, EventArgs e)
{
Response.Write("Submit");
}
}

Nov 19 '05 #8
You need to write the button_click event for the button. You can do that by
double clicking the button in the design view. In that case, your code will
be like
<input type=button runat=server name="button1">. The click event will be
bound to the code behind.

-Baskar BV-
"Perry van Kuppeveld" wrote:
I don't think this will work:

If i click the button script button_click will be executed, and that is not
available.

I will post a new question with the code provided in the previous post, so
it's back on the top.

Thanks anyway
"BASKAR BV" <BA******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hey,

try the code given below.
<script>
function test()
{
document.form1.button1.click();
}
</script>
<form method="post" name="form1" onsubmit="test();" runat=server>
<input type=text>
<input type=button onclick="button_click" runat=server>
</form>
the code will invoke client "test" function which then invokes button1
click
event. So if the user submits the form by pressing enter you could check
for
the format validation and submit or not accordingly.

"Perry" wrote:
I created a new C# webapp and placed the following code in webform class
(In
design mode nothing is changed)
See the dif between pressing enter while the focus is in the textbox, or
clicking the submit button.

Code:
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
TextBox tb = new TextBox( );
tb.TextMode = TextBoxMode.MultiLine;
tb.Attributes["onkeypress"] = "if (event.keyCode == 13) {
document.forms[0].submit(); return false; }";
this.FindControl("form1").Controls.Add(tb);

Button b = new Button();
b.Text = "Submit";
b.Click +=new EventHandler(b_Click);
this.FindControl("form1").Controls.Add(b);
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

private void b_Click(object sender, EventArgs e)
{
Response.Write("Submit");
}
}


Nov 19 '05 #9
Thanks, it's working

Perry


"BASKAR BV" <BA******@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
You need to write the button_click event for the button. You can do that
by
double clicking the button in the design view. In that case, your code
will
be like
<input type=button runat=server name="button1">. The click event will be
bound to the code behind.

-Baskar BV-
"Perry van Kuppeveld" wrote:
I don't think this will work:

If i click the button script button_click will be executed, and that is
not
available.

I will post a new question with the code provided in the previous post,
so
it's back on the top.

Thanks anyway
"BASKAR BV" <BA******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
> Hey,
>
> try the code given below.
> <script>
> function test()
> {
> document.form1.button1.click();
> }
> </script>
> <form method="post" name="form1" onsubmit="test();" runat=server>
> <input type=text>
> <input type=button onclick="button_click" runat=server>
> </form>
> the code will invoke client "test" function which then invokes button1
> click
> event. So if the user submits the form by pressing enter you could
> check
> for
> the format validation and submit or not accordingly.
>
> "Perry" wrote:
>
>> I created a new C# webapp and placed the following code in webform
>> class
>> (In
>> design mode nothing is changed)
>> See the dif between pressing enter while the focus is in the textbox,
>> or
>> clicking the submit button.
>>
>> Code:
>>
>>
>> public class WebForm1 : System.Web.UI.Page
>> {
>> private void Page_Load(object sender, System.EventArgs e)
>> {
>> TextBox tb = new TextBox( );
>> tb.TextMode = TextBoxMode.MultiLine;
>> tb.Attributes["onkeypress"] = "if (event.keyCode == 13) {
>> document.forms[0].submit(); return false; }";
>> this.FindControl("form1").Controls.Add(tb);
>>
>> Button b = new Button();
>> b.Text = "Submit";
>> b.Click +=new EventHandler(b_Click);
>> this.FindControl("form1").Controls.Add(b);
>> }
>>
>> override protected void OnInit(EventArgs e)
>> {
>> InitializeComponent();
>> base.OnInit(e);
>> }
>>
>> private void InitializeComponent()
>> {
>> this.Load += new System.EventHandler(this.Page_Load);
>> }
>>
>> private void b_Click(object sender, EventArgs e)
>> {
>> Response.Write("Submit");
>> }
>> }
>>
>>
>>


Nov 19 '05 #10
Hey, that was my suggestion!!

Haha, just kdding, nice you go it working
"Perry van Kuppeveld" <no*****************@spam.com> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl...
Thanks, it's working

Perry


"BASKAR BV" <BA******@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
You need to write the button_click event for the button. You can do that
by
double clicking the button in the design view. In that case, your code
will
be like
<input type=button runat=server name="button1">. The click event will be
bound to the code behind.

-Baskar BV-
"Perry van Kuppeveld" wrote:
I don't think this will work:

If i click the button script button_click will be executed, and that is
not
available.

I will post a new question with the code provided in the previous post,
so
it's back on the top.

Thanks anyway
"BASKAR BV" <BA******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
> Hey,
>
> try the code given below.
> <script>
> function test()
> {
> document.form1.button1.click();
> }
> </script>
> <form method="post" name="form1" onsubmit="test();" runat=server>
> <input type=text>
> <input type=button onclick="button_click" runat=server>
> </form>
> the code will invoke client "test" function which then invokes button1
> click
> event. So if the user submits the form by pressing enter you could
> check
> for
> the format validation and submit or not accordingly.
>
> "Perry" wrote:
>
>> I created a new C# webapp and placed the following code in webform
>> class
>> (In
>> design mode nothing is changed)
>> See the dif between pressing enter while the focus is in the textbox,
>> or
>> clicking the submit button.
>>
>> Code:
>>
>>
>> public class WebForm1 : System.Web.UI.Page
>> {
>> private void Page_Load(object sender, System.EventArgs e)
>> {
>> TextBox tb = new TextBox( );
>> tb.TextMode = TextBoxMode.MultiLine;
>> tb.Attributes["onkeypress"] = "if (event.keyCode == 13) {
>> document.forms[0].submit(); return false; }";
>> this.FindControl("form1").Controls.Add(tb);
>>
>> Button b = new Button();
>> b.Text = "Submit";
>> b.Click +=new EventHandler(b_Click);
>> this.FindControl("form1").Controls.Add(b);
>> }
>>
>> override protected void OnInit(EventArgs e)
>> {
>> InitializeComponent();
>> base.OnInit(e);
>> }
>>
>> private void InitializeComponent()
>> {
>> this.Load += new System.EventHandler(this.Page_Load);
>> }
>>
>> private void b_Click(object sender, EventArgs e)
>> {
>> Response.Write("Submit");
>> }
>> }
>>
>>
>>


Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dan Weeb | last post by:
Hi All, I have struggled through this far with help from many of you so thanks. I am stuck again. I am really new to this so don't be harsh :-) There are a few problems. You can run the script...
2
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish...
9
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea....
5
by: tshad | last post by:
I have a date validation function that I want to stay at the object I am validating if there is a Validation error, but it always goes to the next object. The Javascript: function...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
2
by: Christian Ista | last post by:
Hello, I found that (see below) to give the focus to a control(textbox) on an asp.net page. There is no easiest way to do that ? Thanks, System.Text.StringBuilder sb = new...
3
by: yuelinniao | last post by:
hi, I have got a simple way to make "textarea" support "auto-submit" when pressing Ctrl+Enter, and tested under both IE and Firefox. The common old method is like this: <form name=form2>...
16
by: Jen | last post by:
Hi. I have this problem that I think should be easy but have been struggling with this for days. I have a list based on a recordset from a database. This list consists of records meeting a certain...
3
by: Jake Barnes | last post by:
I'm researching the Enter key. This is for an Ajax chat application. The designer tells me that she wants people to be able to submit text simply by hitting the Enter key. She wants this to happen...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.