javascript - asp:Button in jQuery dialog box not firing OnClick event -


i have asp:button inside jquery dialog onclick event isn't firing. i'm using postbackurl property navigate page, want set property in onclick event can append query string variable according name of file upload in dialog. posted question dialog earlier, because couldn't post @ all, that's been fixed. clicking button posts fine, , can set postbackurl property in asp markup, or in page_load() of code behind. can't onclick function fire reason, , that's want set postbackurl. here's .aspx...

<form id="frmdialog" runat="server">         <asp:button id="btndisplaydialog" runat="server" text="click display login dialog" onclientclick="showdialog(); return false;" />         <div class="divinnerform"></div>         <div class="divdialog" style="display: none">             <table style="width: 100%;">                 <tr>                     <td>first name: <asp:textbox id="txtfirstname" runat="server" text=""></asp:textbox></td>                     <td>last name: <asp:textbox id="txtlastname" runat="server" text=""></asp:textbox></td>                 </tr>                 <tr>                     <td>                         how old you?                         <asp:dropdownlist id="ddlage" runat="server">                             <asp:listitem value="1">1</asp:listitem>                             <asp:listitem value="2">2</asp:listitem>                             <asp:listitem value="3">3</asp:listitem>                         </asp:dropdownlist>                     </td>                     <td>                         how many siblings have?                         <asp:dropdownlist id="ddlnumbersiblings" runat="server">                             <asp:listitem value="1">1</asp:listitem>                             <asp:listitem value="2">2</asp:listitem>                             <asp:listitem value="3">3</asp:listitem>                             <asp:listitem value="4">4</asp:listitem>                         </asp:dropdownlist>                     </td>                 </tr>                 <tr>                     <td>                         birthday?                         <input type="text" id="datepicker" name="datepicker" />                     </td>                 </tr>                 <tr>                     <td>                         please choose picture upload:                         <asp:fileupload id="fupuserpicture" runat="server" />                     </td>                 </tr>                 <tr>                     <td>                         <asp:button id="btnsubmit" runat="server" text="submit" onclick="btnuserpicture_click" />                     </td>                 </tr>             </table>         </div>     </form> 

...the jquery script displays dialog , places within form...

    function showdialog() {         $('.divdialog').dialog({             modal: true, show: 'slide', width: 500,             open: function (event, ui) {                 $('.divinnerform').append($(this).parent());             }         });     } 

...and code behind onclick function....

 protected void btnuserpicture_click(object sender, eventargs e)         {             string filename = "";             if (fupuserpicture.hasfile)             {                 try                 {                     filename = path.getfilename(fupuserpicture.filename);                     fupuserpicture.saveas(server.mappath("~/images/" + filename));                 }                 catch (exception ex)                 {                 }                 btnsubmit.postbackurl = "~/profile.aspx?pic=" + filename;             }         } 

edit: ok, here's how submit button in dialog renders html. think may problem. can see, javascript onclick provides "profile.aspx" post url, though seems me server side code should execute first , foremost. within form...

<input id="btnsubmit" type="submit" onclick="javascript:webform_dopostbackwithoptions(new webform_postbackoptions("btnsubmit", "", false, "", "profile.aspx", false, false))" value="submit" name="btnsubmit"> 

..and here's how renderes if remove btnsubmit.postbackurl = "~/profile.aspx" page_load() function....

<input id="btnsubmit" type="submit" value="submit" name="btnsubmit"> 

edit 2: ok i've added hidden asp button outside of dialog, , button inside dialog calls javascript function triggers onclick event of hidden button. same thing, javascript function runs fine, btnhidden_click() function does not run! i'm @ total loss, @ point literally have no idea why isn't working. here's new hidden button, outside of dialog div inside of form can see....

 </div>         <asp:button id="btnhidden" runat="server" text="" visible="false" clientidmode="predictable"  onclick="btnhidden_click"/>     </form> 

...here's button inside dialog onclientclick event, i've said runs fine...

                <asp:button id="btnsubmit" runat="server" text="submit" onclientclick="forcebtnhiddenclick(); return false;" /> 

and here's onclick function in code behind btnhidden, though it's same before...

   protected void btnhidden_click(object sender, eventargs e)         {             string filename = "";             if (fupuserpicture.hasfile)             {                 try                 {                     filename = path.getfilename(fupuserpicture.filename);                     fupuserpicture.saveas(server.mappath("~/images/" + filename));                 }                 catch (exception ex)                 {                 }                 response.redirect("~/profile.aspx?pic=" + filename);             }         } 

...and javascript function runs, reason doesn't result in btnhidden_click running...

function forcebtnhiddenclick(e) {     //__dopostback('btnhidden', 'onclick');     $('#btnhidden').trigger('click'); } 

..as can see i've tried both .trigger('click') , __dopostback(), both no avail.

edit: ok, problem

 function forcebtnhiddenclick() {             __dopostback('btnhidden', ''); } 

function, not triggering btnhidden_click event. when make btnhidden visible , click directly, btnhidden_click function runs fine.

edit: after tons of searching, found , got work...

 function forcebtnhiddenclick() {             <%= clientscript.getpostbackeventreference(btnhidden, string.empty) %>;         } 

i don't know why

__dopostback(<%= btnhidden.clientid %>, '')  

doesn't work.

try this

function showdialog() {     $('.divdialog').dialog({         modal: true, show: 'slide', width: 500     });    $(".divdialog").parent().appendto($("form:first")); } 

you should appending divdialog form not empty divinnerform.then button in form , on click event fire happily.

update

try using onclient click.then wire attribute function force post on hidden button.

<asp:button id="btnsubmit" runat="server" text="submit" onclientclick="forceclick();" /> <asp button id="hidbutton" runat="server" onclick="hidbutton_click" />  function forceclick(){  __dopostback('<%#hidbutton.uniqueid %>'); } 

then use event handler hidbutton_click put code.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -