Results 1 to 12 of 12

Thread: [RESOLVED] Calling Button Click From JQuery

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    115

    Resolved [RESOLVED] Calling Button Click From JQuery

    Hey Guys

    i have a JQuery ui dialog box that opens up as a contact form when a link is clicked, which works fine, my problem is trying to submit the information.

    When you click the send button it fires a button click event of another asp:button ive got hidden on the page...

    the post back event fires and the page reloads but the asp:button click event doesn't not fire?

    Heres my code:

    asp:Button is as follows:
    Code:
     <asp:Button  ID="btnSendEnquiry" runat="server" CssClass="" Text="Foo button" OnClick="btnSendEnquiry_Click" />
    jQuery Code (which is at the top of my age)
    Code:
    $(function() {
    
        // Dialog			
        $('#dialog').dialog({
            autoOpen: false,
            width: 500,
            height: 450,
            buttons: {
                "Send": function() {
                    __doPostBack('<&#37;=btnSendEnquiry.UniqueID%>', 'Click');
    
                }
            }
        });
    asp:Button code behind file
    Code:
        Protected Sub btnSendEnquiry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendEnquiry.Click
    
            Dim bResult As Boolean
            bResult = SendEnquiry(tbName.Text, tbCompany.Text, tbEmail.Text, tbContactNumber.Text, tbDescription.Text)
    
            If bResult Then
                MsgBox("got this far so must have sent...?")
            Else
                MsgBox("Ahhhh!...?")
            End If
        End Sub
    Can anyone help me out on this i cant understand why the post back fires but the button even doesnt...?


    Thanks
    Roo

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Calling Button Click From JQuery

    Okay, the obvious question is....

    Why do you have a button hidden on the page, that you are calling the click event from another button, that doesn't really seem to make any sense.

    Gary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    115

    Re: Calling Button Click From JQuery

    Quote Originally Posted by gep13 View Post
    Okay, the obvious question is....

    Why do you have a button hidden on the page, that you are calling the click event from another button, that doesn't really seem to make any sense.

    Gary

    i know it sounds daft (even to me) but the button isn't an asp:button is just a quick fancy jQuery Ui button that gets created when the dialog div is shown. i didnt know any other way of getting to the "send" function in my code behind.


    i did see this way of doing it:
    Code:
    jQuery.ajax({
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: '{}',
        dataType: 'json',
        url: 'MyPage.aspx/SomePageMethod',
        success: function(result){
            alert(result);
        }
    });
    but this kind of shoots me in the foot a bit because its asking for the url and this particular part of the page is on my master page is isgoing to be on every page, so i couldn't just pass in the one page and where would function live.

    also i don't know the syntax to pass my textboxes into the data:{} section because i'm rubbish at jQuery.


    thanks

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Calling Button Click From JQuery

    Hello,

    One other way would be to call a server side method directly, i.e. a Page Method, or a Web Service.

    You can find some information on how this can be achieved here:

    http://www.seoasp.net/post/2008/07/1...-Services.aspx

    Gary

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Calling Button Click From JQuery

    Ah, hold on...

    I have just re-read your post, and it looks like you are already trying that approach.

    How about you explain exactly what this page does, how it gets created, and what the end result should be. From there, we can hopefully get you heading in the right direction.

    Gary

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    115

    Re: Calling Button Click From JQuery

    The page is just a standard information page. There's a link in the navigation bar called 'contact' and this link sits on my master page. when you click the contact link it opens up a hidden div which is a contact form (that also sits om my master page). user fills in the form then press the 'Send' button to send the enquiry.

    Like i said the send button is not an asp:button its just a jquery button created when the div appears. but because the web method is on my master what url do i pass in to get to that method because the jquery is not on one specific page its on the master page?

    That example looked good but in it what is 'fn' and why the paramArray? can you not reference the control (textbox1) directly?

    Thanks

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Calling Button Click From JQuery

    Hey,

    Ok, so if you are just showing a DIV on the page, why can't you use an ASP Button?

    Gary

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    115

    Re: Calling Button Click From JQuery

    Quote Originally Posted by gep13 View Post
    Hey,

    Ok, so if you are just showing a DIV on the page, why can't you use an ASP Button?

    Gary
    Tried that but when i click the button nothing happens at all not even a post back, heres the button code in the master.master page
    HTML Code:
                <asp:TableCell>
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </asp:TableCell>
    and heres the code in the master page code behind file


    Code:
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            SendEnquiry(tbName.Text, tbCompany.Text, tbEmail.Text, tbContactNumber.Text, tbDescription.Text)
    
        End Sub
    i must be missing something so simple but i cant see it. Any suggestions?
    strange thing is if i move this to an actual .aspx page then it works fine but i couldn't possibley duplicate the code on every page that would be a nightmare to manage!!

    Thanks

  9. #9
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Calling Button Click From JQuery

    Do you get a buttonclick when you use your button outside the tablecell?
    Where exactly do you have this on your master page?
    Have you tried to use your own event function using onClick?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Calling Button Click From JQuery

    Hey,

    Is it possible that you can show us the entire code for your page, or create a small sample application that shows this behaviour?

    What you are talking about here is fundamental to ASP.Net, so there must be something else on your page that is stopping the post back. Are there any JavaScript errors on the page when you click the button?

    Gary

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    115

    Re: Calling Button Click From JQuery

    Hi gep

    your right it seems that there's some jQuery stopping the event, if i move the button out side of the dialogue div but keep it on the master page it works fine

    i haven't had chance to have a look a the jquery file yet but ill have a browse and see if i can see where the problem is if not ill just construct my own pop out div and use the jquery css styles.


    Thanks for both your help

    Roo

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Calling Button Click From JQuery

    Hey,

    You should be able to use the built in JavaScript debugger, available in all the main browsers, to try and isolate where the problem is.

    Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width