473,385 Members | 1,907 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,385 software developers and data experts.

postback in asp.net 2.0

hello,
I am using a form which has multiple buttons(asp server controls) say B1, B2
and B3. The postabck gets fired on B1 click whereas I want it to happen on B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and force
it to fire on B3 click. i heard asp.net has a simple way to handle this and
there is no need to write a _dopostback javascript function.

Can somebody help me on this?

Thanks

Nov 19 '05 #1
5 1448
Set the UseSubmitPostback Property value to false for B1 & B2 and true for
B3
"getdotnet" <ge*******@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
hello,
I am using a form which has multiple buttons(asp server controls) say B1,
B2
and B3. The postabck gets fired on B1 click whereas I want it to happen on
B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and
force
it to fire on B3 click. i heard asp.net has a simple way to handle this
and
there is no need to write a _dopostback javascript function.

Can somebody help me on this?

Thanks

Nov 19 '05 #2
I assume that you are looking for something like pressing the enter key
should fire a button click even other than the default button.
if my assumption is correct then the answer is in a simple client-side
javascript function called whenever a button is pressed, that, if the button
pressed is the Enter key, cancels the default submit and simulates a click on
the wanted button. Here's the function, that you can copy and paste as-is
into your ASPX pages, or that you can paste into a separate .js file,
referenced by any ASPX page that needs it:

< language="javascript">
function KeyDownHandler(btn)
{
// process only the Enter key
if (event.keyCode == 13)
{
// cancel the default submit
event.returnValue=false;
event.cancel = true;
// submit the form by programmatically clicking the specified button
btn.click();
}
}
< /script>

Now, in the input controls declaration you just have to call this function
when a button is pressed, by handling the onKeyPressed client-side event, and
pass a reference to the default button:
< runat="server" id="FN" onkeydown= "KeyDownHandler(DefButton)">

--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net

"Any one who has never made a mistake has never tried anything new" - Einstein
"getdotnet" wrote:
hello,
I am using a form which has multiple buttons(asp server controls) say B1, B2
and B3. The postabck gets fired on B1 click whereas I want it to happen on B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and force
it to fire on B3 click. i heard asp.net has a simple way to handle this and
there is no need to write a _dopostback javascript function.

Can somebody help me on this?

Thanks

Nov 19 '05 #3
Thanks !..but your assumption is wrong. I am working on a situation where the
user actually clicks a button.

"Kannan.V [MCSD.net]" wrote:
I assume that you are looking for something like pressing the enter key
should fire a button click even other than the default button.
if my assumption is correct then the answer is in a simple client-side
javascript function called whenever a button is pressed, that, if the button
pressed is the Enter key, cancels the default submit and simulates a click on
the wanted button. Here's the function, that you can copy and paste as-is
into your ASPX pages, or that you can paste into a separate .js file,
referenced by any ASPX page that needs it:

< language="javascript">
function KeyDownHandler(btn)
{
// process only the Enter key
if (event.keyCode == 13)
{
// cancel the default submit
event.returnValue=false;
event.cancel = true;
// submit the form by programmatically clicking the specified button
btn.click();
}
}
< /script>

Now, in the input controls declaration you just have to call this function
when a button is pressed, by handling the onKeyPressed client-side event, and
pass a reference to the default button:
< runat="server" id="FN" onkeydown= "KeyDownHandler(DefButton)">

--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net

"Any one who has never made a mistake has never tried anything new" - Einstein
"getdotnet" wrote:
hello,
I am using a form which has multiple buttons(asp server controls) say B1, B2
and B3. The postabck gets fired on B1 click whereas I want it to happen on B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and force
it to fire on B3 click. i heard asp.net has a simple way to handle this and
there is no need to write a _dopostback javascript function.

Can somebody help me on this?

Thanks

Nov 19 '05 #4
I cannot see any UseSubmitPostback property for a button but i do see
useSubmitBehavior property. I set that property to false for B1 and B2. and
now i get a javascript error on clicking B1 and B2

theform._EVENTTARGET is null or not an object

"Sanjay Pais" wrote:
Set the UseSubmitPostback Property value to false for B1 & B2 and true for
B3
"getdotnet" <ge*******@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
hello,
I am using a form which has multiple buttons(asp server controls) say B1,
B2
and B3. The postabck gets fired on B1 click whereas I want it to happen on
B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and
force
it to fire on B3 click. i heard asp.net has a simple way to handle this
and
there is no need to write a _dopostback javascript function.

Can somebody help me on this?

Thanks


Nov 19 '05 #5
Why don't you simply have B1's OnClick point to the same event handler that
B3 uses?

-Brock
DevelopMentor
http://staff.develop.com/ballen
hello,
I am using a form which has multiple buttons(asp server controls) say
B1, B2
and B3. The postabck gets fired on B1 click whereas I want it to
happen on B3
click. I know that by default the first button on a page is set as the
'submit' button and that is the reason for this behaviour.
Now teh question is, how can i prevent postback firing on B1 click and
force
it to fire on B3 click. i heard asp.net has a simple way to handle
this and
there is no need to write a _dopostback javascript function.
Can somebody help me on this?

Thanks


Nov 19 '05 #6

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

Similar topics

5
by: Matthew Louden | last post by:
I created simple ASP.NET web application to test how AutoPostBack property in a web control works. I set AutoPostBack property to be true of a web control. When I run the application, here's the...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
8
by: walesboy | last post by:
greetings - I have a btnSubmit button with a Handles btnSubmit.click which works great if all the user does is click that button. But, if the user ALSO changes a text box on the page (which...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
2
by: Wizzard | last post by:
I have a repeater with and imagebutton on a page useing VS2005 ASP.Net 2.0 <asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate> <div> <asp:ImageButton ImageUrl="button.gif"...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
2
by: Nathan Sokalski | last post by:
I have a DataList in which the ItemTemplate contains two Button controls that use EventBubbling. When I click either of them I receive the following error: Server Error in '/' Application....
7
by: Tony Girgenti | last post by:
Hello. I'm trying to undetrstand ASP.NET 2.0 and javascript. When i have a button and i click on it and i see the web broswer progress bar at the bottom do something, does that mean that there...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.