$(document).ready(function () {
$("#Div_1").show();
$("#Div_2").hide();
$('#Button1').click(function () {
$("#Div_1").hide();
$("#Div_2").show();
return false;
});
});
in the above code jquery code is working fine but event is not firing
-
which event ? Server side / client side ? can you please elaborate on your requirement and issue being faced ?AYK– AYK2013年06月21日 10:29:29 +00:00Commented Jun 21, 2013 at 10:29
-
$(document).ready(function () { $("#Div_1").show(); $("#Div_2").hide(); $('#Button1').click(function () { $("#Div_1").hide(); $("#Div_2").show(); return false; }); protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Hello"; } Exact codeRajesh Gonugunta– Rajesh Gonugunta2013年06月21日 10:29:42 +00:00Commented Jun 21, 2013 at 10:29
-
so you want to say that the server side event does not get fired, right ?AYK– AYK2013年06月21日 10:30:39 +00:00Commented Jun 21, 2013 at 10:30
-
Better add the code to your post instead of writing code here.Freddy– Freddy2013年06月21日 10:30:46 +00:00Commented Jun 21, 2013 at 10:30
-
So the jQuery click handler is not being executed?Konstantin Dinev– Konstantin Dinev2013年06月21日 10:32:17 +00:00Commented Jun 21, 2013 at 10:32
1 Answer 1
In your JavaScript code you attach a client-side click handler to the button and then return false
at the end of the handler. This prevents the click event from continuing up the DOM, which is also probably causing it to not fire the built-in post-back code.
Try removing the return false
statement in order to fire the post-back to the server.
Be aware, however, that this might not behave as you expect. Whatever you're doing client-side (showing/hiding elements it would appear) will only happen for a brief instant before the code posts to the server and the page refreshes, losing those client-side changes.