hi all, i've one problem with the jquery

i am hiding a <div> using style=display:none;

and when i clicked a button whose id is lnkbtnUnitAdd, i want to show the above div

but i've written some code on OnClick event of the button,

since the below function is returning false, i am not able to execute the code on server side,

can anyone tell me how to execute the both functions,

when i set the return =true; the div tag is not clearly seen and more over it just showing up and closing (like toggle)

function Toggledivs()

    {                 

       $("#lnkbtnUnitAdd").click(function () {

         $("#divUnit").show("slow");  return false;              

         });

    }

Recommended Answers

All 26 Replies

This is not making much sense to me. You only want to bind the #lnkbtnUnitAdd click event to the button when you call the function? Usually when I see this being done it is in a .ready function call like so:

$(document).ready(function()
{
    $("#lnkbtnUnitAdd").click(function () {
        $("#divUnit").show("slow"); return false;
    });
});

Even if i used $(document).ready(functio())

as the value returning is false, i am not able to enter into the button OnClick event (in which i've written some server code to enable and disable some other buttons)

Try calling the function Toggledivs() on onclick in
the tag like onclick="func1();Toggledivs();"

function Toggledivs()
{
   $("#divUnit").show("slow");
}

Try calling the function Toggledivs() on onclick in
the tag like onclick="func1();Toggledivs();"

function Toggledivs()
{
   $("#divUnit").show("slow");
}

Nope it is not working, i think the asp button won't work with two functions in OnClick event

You could call the other function within the jQuery function..

function Toggledivs()
{
   $("#divUnit").show("slow",function(){
    
    func1();
   });
}

but when i've written the below code

function Toggledivs() { 

setTimeout(function() {

         alert('hi');

         $("#divUnit").show("slow");},0);

    } 

it worked, but the problem is how to run the code with out alert

I don't see why the setTimeout function would make a difference unless you have some type of interval that is interfering with the process. I suppose that this is possible. I know that I am reaching but maybe that is what is happening, the alert is pausing whatever process is going on long enough for jQuery to kick off the popup, maybe.

I do know that a workaround like you have there is going to a pain to support cross browser.

I don't see why the setTimeout function would make a difference unless you have some type of interval that is interfering with the process. I suppose that this is possible. I know that I am reaching but maybe that is what is happening, the alert is pausing whatever process is going on long enough for jQuery to kick off the popup, maybe.

I do know that a workaround like you have there is going to a pain to support cross browser.

R0bb0b, can u give any suggestion to skip alert boxes, what do u mean by any other processes, i am using nested update panels and simple code to enable and disable some buttons and dropdowns filling,
we are mainly using our applicaton in internet explorer only so i am not worrying about cross browsers compatibility.

so if you take "alert('hi');" out of your code, it doesn't work but it does work with it?

and this doesn't work?

function Toggledivs()
{
   $("#divUnit").show("slow");
}

Have you tried it in Firefox, with the error console running along side?

so if you take "alert('hi');" out of your code, it doesn't work but it does work with it?

yes! U r correct

yes! U r correct

mainly our applications use internet explorer, so i didn't tried it in firefox,
and the code above is not working without alert

mainly our applications use internet explorer, so i didn't tried it in firefox,
and the code above is not working without alert

i TRIED IT IN CHROME, BUT STILL THE RESULT IS SAME

can I see your page, is it live?

if so, chances are I can tell you exactly what's wrong.

can i see your page, is it live?

If so, chances are i can tell you exactly what's wrong.

i think it is in my localhost! We didn't even moved to production,
can i post the code! I.E.., MY ASPX AND .CS PAGES

pLEASE CAN U LOOK INTO THE ATTACHED FILE

i think it is in my localhost! We didn't even moved to production,
can i post the code! I.E.., MY ASPX AND .CS PAGES

I don't want the aspx stuff, really all I am interested in is the html source, and the javascript files. If that is too large you can zip them and attach the zip file.

[edit] let me see what you've got there

this is not extracting for me. It just extracts to another zip file and then another. I don't know if it is because I am on a mac but I can't open it.

the error that I get when extracting it is "End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive."

Apparently, whatever program you used to zip this with created an invalid zip format.

I don't want the aspx stuff, really all I am interested in is the html source, and the javascript files. If that is too large you can zip them and attach the zip file.

[edit] let me see what you've got there

FYI, just see the Onclick event of first panel itself i.e.., Location Panel

I have to go but I would start with this:

function Toggledivs()
{
   $("#divUnit").show("slow");
}

Then eliminate all other javascript from the page except the jQuery library. If it starts working then, start adding the javascript back to the page little by little until it breaks again. Once it does, you will know what is corrupting the jQuery.

the error that I get when extracting it is "End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive."

Apparently, whatever program you used to zip this with created an invalid zip format.

Just change the extension to rar, i used winrar and later found that it is not compatible with daniweb attachment extensions so changed the extension to zip,
i am posting u the zip file

Just change the extension to rar, i used winrar and later found that it is not compatible with daniweb attachment extensions so changed the extension to zip,
i am posting u the zip file

I've tried what u said for 2 hrs!
i've deleted all the javascript code from my page including the references but excluding ajax and asp controls, but no progress the function is not working, here i am attaching my aspx page please help

The probelm would appear to be caused by one of two things, maybe both:

  1. OnClientClick and onClick in the same tag (several times), where OnClientClick calls the recursive jQuery function .show . I'm pretty certain that OnClientClick wasn't conceived (by the gnomes of Redmond) with this type of usage in mind and maybe IE has a problem with it.
  2. Toggledivs doesn't return true . Its return value is "undefined", which is falsy.

This may work, though you lose the nice fade effet :

function Toggledivs() {
    $("#divUnit").css('display', 'block');//nothing fancy, just a straightforward, synchronous statement.
    return true;
}

with :

<asp:LinkButton ID="lnkbtnUnitAdd" runat="server" OnClientClick="return Toggledivs()" OnClick="lnkbtnAdd_Click" Text="Add" ></asp:LinkButton>
<!-- Note: "return Toggledivs()" -->

There may be a way to have the nice jQuery fadein effect and the other functionality but my ASP is way too rudimentary to offer definitive advice.

You could try this variant of R0bb0b's first suggestion:

$(document).ready(function() {
    $("#lnkbtnUnitAdd").click(function () {
        $("#divUnit").show("slow");
        return true;//*true* not false
    });
});

with :

<asp:LinkButton ID="lnkbtnUnitAdd" runat="server" OnClientClick="return Toggledivs()" OnClick="lnkbtnAdd_Click" Text="Add" ></asp:LinkButton>

But I'm not certain how this would interact with the ASP button. Would the server-side lnkbtnAdd_Click call still be made?

It would be more likely to succeed with :

$(document).ready(function() {
    $("#lnkbtnUnitAdd").click(function () {
        $("#divUnit").show("slow", function(){
            // Here, call ASP function lnkbtnAdd_Click
        });
        return false;//back to *false*
    });
});

But I don't have a clue how to call ASP's lnkbtnAdd_Click from regular javascript.

Personally, I would want to ditch ASP buttons in favour of standard HTML with jQuery's AJAX functionality to perform the server-side communication. But since you probably have a large investment in ASP code, this is probably not a such a good idea.

Hope something in there works for you.

Airshow

I've tried what u said for 2 hrs!
i've deleted all the javascript code from my page including the references but excluding ajax and asp controls, but no progress the function is not working, here i am attaching my aspx page please help

I don't know what to do with this aspx bundle, I am a javascript/php dev. If I can't see your source then I am not going to be able to figure out what the problem is.

In Firefox, on the web page in question do two things:
1. click view->Page Source, copy the result and attach it as a text file

2. with the Firefox add-on called "web developer", click "information"->"view javascript", copy the result and attach it as a text file

Robbob! I've Replied to the above comment and don't know what happened to it, I've solved the issue, it is raised due to Update Panel and as u said ur a JavaScript and php programmer, i am sorry in troubling u, but at last the problem get solved,
I won't forget ur efforts airshow :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.