postback in asp.net 2.0

G

Guest

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
 
S

Sanjay Pais

Set the UseSubmitPostback Property value to false for B1 & B2 and true for
B3
 
G

Guest

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
 
G

Guest

Thanks !..but your assumption is wrong. I am working on a situation where the
user actually clicks a button.
 
G

Guest

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
 
B

Brock Allen

Why don't you simply have B1's OnClick point to the same event handler that
B3 uses?
 
G

Guest

Because i do not want B1 to do what B2/B3 Does.

Well here is the situation.
I have a panel 1 which hosts a user control.
click of B1 shows panel 2. I do some data input action in panel 2 and click
on B2. I want a postback to fire on B2 click so that the control in panel 1
shows the modified data.

But in my case the control is showing the new modified data on B1 click and
not B2 click!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top