|
-
Apr 14th, 2011, 12:55 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] call JQuery from ASP.net Button Click
hay there,
i am new to JQuery,
so i wounder if there is a way to call JQuery method after button click from server side event,
here is what i really try to do,
the user will click on the login Button, and i will check his login name and his user name on the server side,
then i will call the JQuery function to execute slideToggle for a Div
is there a way to do such a thing
here is my JQuery function
Code:
function LoginError() {
$(document).ready(function() {
$("LoginButton").click(function() {
$(".DivError").slideToggle("slow");
return false;
});
});
}
Code:
bool loginFlag = false;
if(!loginFlag){
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(),
"startup", "<script type=\"text/javascript\">LoginError();</script>");
}
but there is nothing happened,
i think i am missing something 
thanks alot.
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 14th, 2011, 02:01 AM
#2
Re: call JQuery from ASP.net Button Click
You can just run this on the client side:
JavaScript Code:
function LoginError() {
$(".DivError").slideToggle("slow");
}
and then call it from the server-side using ClientScript.RegisterClientScriptBlock().
You don't want to bind it to the button click event because the button is calling the server-side code to authenticate the user. If you did that, the div would toggle every time. Also, returning "false" from a client script event handler (the button click event) will prevent the asp.net button postback from occurring to run the server-side click event.
You also don't need the document.ready() here because the client-side function won't be called until the page/DOM has already loaded fully (which is what the document.ready waits for).
-
Apr 14th, 2011, 02:20 AM
#3
Thread Starter
Frenzied Member
Re: call JQuery from ASP.net Button Click
ok, thanks tr333
i used this now
Code:
protected void Button2_Click(object sender, EventArgs e)
{
bool flag = true;
if (flag)
{
this.ClientScript.RegisterClientScriptBlock(this.Page.GetType(),
"Error", "$(document).ready(function() {$(\".flip\").click(function() {$(\".panel\").slideToggle(\"slow\");});});", true);
}
}
i can see the div for less than 1/3 sec,
this when i remove the return false;
i can see the Div from the second click if the return false; exist
so i don't actually know where is the problem
Last edited by avrail; Apr 14th, 2011 at 02:25 AM.
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 14th, 2011, 02:30 AM
#4
Re: call JQuery from ASP.net Button Click
If you remove the document.ready from the script you are sending from the server-side (remeber that DOM is already loaded when doing this, so document.ready is not required), then you would get:
JavaScript Code:
$('.flip').click(function() {
$('.panel').slideToggle('slow');
});
Do you want to only have the panel toggle visibility when clicking the ".flip", and not immediately after sending this client-script from the server-side?
Don't forget that this click event handler on ".flip" will only be added after the script is sent from the server-side button click event.
-
Apr 14th, 2011, 02:43 AM
#5
Thread Starter
Frenzied Member
Re: call JQuery from ASP.net Button Click
hay tr333,
thanks again
the flip css class if the button
Code:
<asp:Button ID="Button2" Text="Show Refat and Hide Karim" runat="server" CssClass="flip"
onclick="Button2_Click" />
what i need is when the user click the login button and after the check for the login on the server done
i want show the Div immediately if the user login failed
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 14th, 2011, 07:31 PM
#6
Re: call JQuery from ASP.net Button Click
You can remove CssClass="flip" from the asp:button, since this button is going to call the server-side button click event to handle the login validation. If the login validation fails inside this server-side event, then you just need to pass the script back in a RegisterClientScriptBlock() to show the div.
JavaScript Code:
$('.panel').slideToggle('slow');
You don't need any client-side click event handlers, because the validation is all being done on the server-side.
-
Apr 15th, 2011, 01:09 PM
#7
Thread Starter
Frenzied Member
Re: call JQuery from ASP.net Button Click
you are right tr333
your last post solved my problem,
i think i need to read more before i use JQuery
thanks a lot,
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 16th, 2011, 07:27 AM
#8
Re: [RESOLVED] call JQuery from ASP.net Button Click
The best way to learn is practice
-
Apr 16th, 2011, 08:31 AM
#9
Thread Starter
Frenzied Member
Re: [RESOLVED] call JQuery from ASP.net Button Click
you are right
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 24th, 2011, 02:40 PM
#10
Re: [RESOLVED] call JQuery from ASP.net Button Click
Out of curiousity tr333, do you have any links for where you picked up jQuery? It has been on my list of things to pick up for a while, but not really got round to it yet 
Gary
-
Apr 24th, 2011, 06:12 PM
#11
Thread Starter
Frenzied Member
Re: [RESOLVED] call JQuery from ASP.net Button Click
i begin with w3schools, and i think it is a good beginning for me
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Apr 25th, 2011, 12:38 AM
#12
Re: [RESOLVED] call JQuery from ASP.net Button Click
That used to be the same for me as well, although I have recently heard some criticism for w3schools, and htmldog:
http://htmldog.com/
Is a better source for HTML and CSS related information, so I am curious as to whether the jQuery information at w3schools is any good?!?
Gary
-
Apr 25th, 2011, 04:41 AM
#13
Re: [RESOLVED] call JQuery from ASP.net Button Click
For jQuery I've just used the jQuery website and Google, browsing through the jQuery API reference to see what it can do. Also useful is jQueryUI and the upcoming jQuery Mobile.
For generic HTML/CSS/JavaScript reference I always use Mozilla Developer Network. Another great reference is Dev.Opera which has some great articles on efficient JavaScript development, among other things.
I started learning jQuery when I needed to do a deep-copy merge of two objects and found that prototype.js (which I was using at the time) could only do shallow-copy merging.
Last edited by tr333; Apr 25th, 2011 at 04:58 AM.
-
Apr 25th, 2011, 06:26 AM
#14
Re: [RESOLVED] call JQuery from ASP.net Button Click
Thanks for the links!
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|