开发者

Handle two events on button click

开发者 https://www.devze.com 2023-01-08 11:42 出处:网络
I am a bit new to the asp.net/jQuery game, and I seem to be having difficulty. I am using colorbox to make a modal window popup, and I want an upload picture form on that modal window. I have a button

I am a bit new to the asp.net/jQuery game, and I seem to be having difficulty. I am using colorbox to make a modal window popup, and I want an upload picture form on that modal window. I have a button to open up the add photo form:

<a href="#" class="addpicture">Add/Edit picture(s)</a><br />
 <script>
        $(document).ready(function () {
            $(".addpicture").colorbox({ width: "50%", inline: true, href: "#page1" });
        });
 </script>

Thus far my modal window is working perfectly, and is displaying the following upload form and next button:

<asp:FileUpload ID="picup" runat="server" class="upload" /><br />
        <asp:Button ID="Button1" type="button" runat="server" Text="Next Page" class="nextpage" />

Here's where I am stuck; I am trying to have the next button upload the picture, and move to a second modal window, which I am going to implement a crop function on. The problem is, to do this, I need a jquery event handler:

$(".nextpage").colorbox({ width: "50%", inline: true, href: "#page2" });

I also need a serverside event handler to do the actual upload:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        picup.PostedFile.SaveAs("\Pictures\1-a.jpg")
    Catch ex As Exception
        Response.Write("Upload Failed")
    End Try
End Sub

Howeve开发者_Go百科r, when I put in a breakpoint, this event handler is never firing. A possible solution I thought up is to make a hidden button that fires the javascript, and click that button from vb, but I couldn't figure out how to click a button from vb. Is there something I'm doing fundamentally wrong? Is there a good way to accomplish what I want?

Edit: I have changed the way I am doing this, instead of multiple modal windows, I am loading a separate page in an iframe on the modal window, then I can have a postback without reloading the main page. Thank you for your help.


When uploading files with the fileUpload control you need a postback, otherwise the event will never fire.

  • There are a couple of plugins por jQuery that promise to enable uploading via ajax but i've never tried any.


In jquery bind() method lets you attach different behaviors to an element :

Example:

$("#a").bind("mouseover mouseout", function(e){
     $(this).text($(this).text() + " event triggered " );
});
0

精彩评论

暂无评论...
验证码 换一张
取 消