链接按钮没有触发但按钮正在工作

时间:2015-02-16 12:24:49

标签: c# ajax linkbutton

我有两个页面inbox.aspx和compose.aspx 通过ajax我正在加载收件箱页面中的div内加载撰写页面 所以我面临一个问题与形式因为我在收件箱和撰写页面的母版页中使用表单 当我加载撰写页面时,我将有两个嵌套形式:( 我试图省略它但是当我把asp控件放在里面时,页面将不会加载它 到目前为止,每件事情都没有错误,但在撰写页面时,我点击它时有链接按钮我有错误 (递归过多,传递给getElementById()的空字符串) 并且它没有触发,但是asp:按钮标签工作得很好 这是代码

  

inbox.aspx

<div class="row email">
                                <div id="list-toggle" class="col-md-2">
                                    <ul class="list-unstyled">
                                        <li class="composeBtn">
                                            <a href="javascript:;" data-title="Compose" class="btn Compose btn-danger">Compose
                                            </a>
                                        </li>
                                    </ul>
                                    <ul class="emailNav nav nav-pills nav-stacked margin-bottom-10">
                                        <li class="inbox active">
                                            <a href="javascript:;" data-title="Inbox">
                                                <i class="fa fa-inbox fa-fw"></i>Inbox (2)
                                            </a>
                                        </li>
                                        <li class="starred">
                                            <a href="javascript:;" data-title="Starred">
                                                <i class="fa fa-star fa-fw"></i>Starred
                                            </a>
                                        </li>
                                        <li class="sent">
                                            <a href="javascript:;" data-title="Sent">
                                                <i class="fa fa-mail-forward fa-fw"></i>Sent Items
                                            </a>
                                        </li>
                                        <li class="draft">
                                            <a href="javascript:;" data-title="Draft">
                                                <i class="fa fa-files-o fa-fw"></i>Drafts
                                            </a>
                                        </li>
                                        <li class="spam">
                                            <a href="javascript:;" data-title="Spam">
                                                <i class="fa fa-ban fa-fw"></i>Spam
                                            </a>
                                        </li>
                                        <li class="trash">
                                            <a href="javascript:;" data-title="Trash">
                                                <i class="fa fa-trash-o fa-fw"></i>Trash
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                                <div class="col-md-10">
                                    <div class="emailContent"></div>
                                </div>
                            </div>
  

JavaScript的   var Inbox = function(){

var main_content = $('.emailContent');
/*-----------------------------------------------------------------------------------*/
/*  Show single email view
/*-----------------------------------------------------------------------------------*/
var showSingleEmail = function (el, name, resetMenu) {
    alert('');
    var url = 'inbox_email.html';
    main_content.html('');
    toggleButton(el);        
    $.ajax({
        type: "GET",
        cache: false,
        url: url,
        dataType: "html",
        success: function(res) 
        {
            toggleButton(el);               
            main_content.html(res);                
            App.initUniform();
        },
        error: function(xhr, ajaxOptions, thrownError)
        {
            toggleButton(el);
        },
        async: false
    });
}

/*-----------------------------------------------------------------------------------*/
/*  Show WYSIWYG Editor
/*-----------------------------------------------------------------------------------*/
var showWYSIWYG = function () {
    alert('');
    function initToolbarBootstrapBindings() {
      var fonts = ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier', 
            'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
            'Times New Roman', 'Verdana'],
            fontTarget = $('[title=Font]').siblings('.dropdown-menu');
      $.each(fonts, function (idx, fontName) {
          fontTarget.append($('<li><a data-edit="fontName ' + fontName +'" style="font-family:\''+ fontName +'\'">'+fontName + '</a></li>'));
      });
      $('a[title]').tooltip({container:'body'});
        $('.dropdown-menu input').click(function() {return false;})
            .change(function () {$(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');})
        .keydown('esc', function () {this.value='';$(this).change();});

      $('[data-role=magic-overlay]').each(function () { 
        var overlay = $(this), target = $(overlay.data('target')); 
        overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
      });
      if ("onwebkitspeechchange"  in document.createElement("input")) {
        var editorOffset = $('#editor').offset();
        $('#voiceBtn').css('position','absolute').offset({top: editorOffset.top, left: editorOffset.left+$('#editor').innerWidth()-35});
      } else {
        $('#voiceBtn').hide();
      }
    };
    function showErrorAlert (reason, detail) {
        var msg='';
        if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
        else {
            console.log("error uploading file", reason, detail);
        }
        $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
         '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
    };
    initToolbarBootstrapBindings();  
    $('#editor').wysiwyg({ fileUploadError: showErrorAlert} );
}

/*-----------------------------------------------------------------------------------*/
/*  Show Inbox view
/*-----------------------------------------------------------------------------------*/
var showInbox = function (el, name) {
    alert('');
    var url = 'inbox_main.html';      
    main_content.html('');
    toggleButton(el);
    $.ajax({
        type: "GET",
        cache: false,
        url: url,
        dataType: "html",
        success: function(res) 
        {
            toggleButton(el);               
            main_content.html(res);
            App.initUniform();
        },
        error: function(xhr, ajaxOptions, thrownError)
        {
            toggleButton(el);
        },
        async: false
    });
}

/*-----------------------------------------------------------------------------------*/
/*  Show email reply view
/*-----------------------------------------------------------------------------------*/
var showEmailReply = function (el) {
    alert('');
    var url = 'inbox_email_reply.html'; 
    main_content.html('');
    toggleButton(el);
    $.ajax({
        type: "GET",
        cache: false,
        url: url,
        dataType: "html",
        success: function(res) 
        {
            toggleButton(el);               
            main_content.html(res);
            handleCCControl();
            handleCCBCC();
            showWYSIWYG();
            $('#editor').html($('#reply-content').html());
            $('#reply-content').hide();                
            App.initUniform();
            $('#editor').focus();
        },
        error: function(xhr, ajaxOptions, thrownError)
        {
            toggleButton(el);
        },
        async: false
    });
}
/*-----------------------------------------------------------------------------------*/
/*  Show Compose view
/*-----------------------------------------------------------------------------------*/
var showCompose = function (el) {
    alert('');
    var url = 'InboxCompose.aspx';
    main_content.html('');

   //toggleButton(el);
    //
    $.ajax({
        type: "POST",
        cache: false,
        url: url,

        //dataType: "application/x-www-form-urlencoded; charset=utf-8",
        success: function(res) 
        {
           // $(".emailContent").load("InboxCompose.aspx  #EmailComposeContent");

           // toggleButton(el);
            //$(".emailContent").load("InboxCompose.aspx");
            main_content.html(res);
          //  showWYSIWYG();
        //  handleCCBCC();
        //    $('#editor').focus();                
         //   App.initUniform();
        },
        error: function(xhr, ajaxOptions, thrownError)
        {
            toggleButton(el);
        },
        async: false
    });
   // App.setPage("Teacher");  //Set current page
  //  App.setAction("ComposeEmail");  //Set current page
  //  App.init(); //Initialise plugins and elements
}
/*-----------------------------------------------------------------------------------*/
/*  Show Compose view
/*-----------------------------------------------------------------------------------*/
var handleCCBCC = function () {
    alert('');
    $('.emailCompose .address').on('click', '.emailCC', function () {
        handleCCControl();
    });
    $('.emailCompose .address').on('click', '.emailBCC', function () {
        handleBCCControl();
    });
}
/*-----------------------------------------------------------------------------------*/
/*  Show Compose view
/*-----------------------------------------------------------------------------------*/
var handleCCControl = function () {
    alert('');
    var the = $('.emailCompose .address .emailCC');
    var input = $('.emailCompose .inputCC');
    the.hide();
    input.show();
    $('.close', input).click(function () {
        input.hide();
        the.show();
    });
}
/*-----------------------------------------------------------------------------------*/
/*  Show Compose view
/*-----------------------------------------------------------------------------------*/
var handleBCCControl = function () {
    alert('');
    var the = $('.emailCompose .address .emailBCC');
    var input = $('.emailCompose .inputBCC');
    the.hide();
    input.show();
    $('.close', input).click(function () {
        input.hide();
        the.show();
    });
}

/*-----------------------------------------------------------------------------------*/
/*  Toggle button
/*-----------------------------------------------------------------------------------*/
var toggleButton = function (el) {
    alert('');
    if (typeof el == 'undefined') {
        return;
    }
    if (el.attr("disabled")) {
        el.attr("disabled", false);
    } else {
        el.attr("disabled", true);
    }
}

return {
    init: function () {
         alert('');
        ///* Show main inbox screen */
        //$('.emailNav > li.inbox > a').click(function () {
        //    showInbox($(this), 'inbox');
        //});

        /* Show compose screen */
        $('.email .composeBtn').on('click', 'a.Compose', function () {
            showCompose($(this));
        });

        ///* Show email reply screen */
        //$('.email').on('click', '.replyBtn', function () {
        //    showEmailReply($(this));
        //});

        ///* Show single email screen */
        //$('.emailContent').on('click', '.viewEmail', function () {
        //    showSingleEmail($(this));
        //});

        ///* Handle CC control links */
        //$('.emailCompose .address').on('click', '.emailCC', function () {
        //    handleCCControl();
        //});

        ///* Handle BCC control links */
        //$('.emailCompose .address').on('click', '.emailBCC', function () {
        //    handleBCCControl();
        //});

        ///* Show main inbox for the first load */
        //$('.emailNav > li.inbox > a').click();
    }
};

}();

  

Compose.aspx

 <html>

   <body>
      <form id="form" runat="server"  method="get">
          <div id="EmailComposeContent" class="emailCompose form-horizontal">
          <div class="emailField" >
              <label class="control-label  pl-none">
                  <span>To:</span>
              </label>
              <div class="fields col-md-11">
                  <asp:TextBox type="hidden" class="bigdrop js-data-example-ajax col-md-9 selectDynamic noborder" runat="server"
                      data-groupname="ToGroup" data-groupcontrol="ToGroupList"
                      ID="TextBoxToIDs" data-url="InboxCompose.aspx/GetXMLData" value="16340"></asp:TextBox>
                  <div class="col-md-3">
                      <ul id="ToGroupList" class="pagination  pagination-sm mb-none  mt-none">
                          <li id="ParentGroup" class="anchor Sections "
                              onclick="setSection(this);">
                              <span class='f-lightergray'><span data-original-title="Parent" data-title="P" class="text">P</span>
                                  <input id='RadioParentGroup' name="ToGroup" checked="checked" type="radio" value="3" style="display: none" /></span>
                          </li>
                          <li id="StudentGroup" class="anchor Sections "
                              onclick="setSection(this);">
                              <span class='f-lightergray'><span data-original-title="Student" data-title="S" class="text">S</span>
                                  <input id='RadioStudentGroup' name="ToGroup" type="radio" value="2" style="display: none" /></span>
                          </li>
                          <li id="AdviserGroup" class="anchor Sections "
                              onclick="setSection(this);">
                              <span class='f-lightergray'><span data-original-title="Adviser" data-title="A" class="text">A</span>
                                  <input id='RadioAdviserGroup' name="ToGroup" type="radio" value="5" style="display: none" /></span>
                          </li>

                      </ul>
                  </div>
              </div>



          </div>


         <div class="emailField">
            <label class="control-label  ">
                Title:</label>
            <div class="fields col-md-9">
               <asp:TextBox CssClass="form-control" ID="TextBoxTitle" runat="server"   type="text" ></asp:TextBox>
            </div>
         </div>

          <div class="emailField">
            <label class="control-label ">
                Expiry Date:</label>
            <div class="fields col-md-4">
          <asp:TextBox CssClass="form-control datepicker" ID="TextBoxExpiryDate" runat="server"   type="text" ></asp:TextBox>
             </div>
               <label class="control-label ">
                Publish Date:</label>
            <div class="fields col-md-4"> 
                <asp:TextBox CssClass="form-control datepicker" ID="TextBoxPublishDate" runat="server"   type="text" ></asp:TextBox>
             </div>
         </div>
         <div class="emailField">
            <div class="divide-20"></div>
            <div id="alerts"></div>
            <div class="btn-toolbar" data-role="editor-toolbar" data-target="#editor">
               <div class="btn-group">
                  <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="Font"><i class="fa fa-font"></i><b class="caret"></b></a>
                  <ul class="dropdown-menu">
                  </ul>
               </div>
               <div class="btn-group">
                  <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="fa fa-text-height"></i>&nbsp;<b class="caret"></b></a>
                  <ul class="dropdown-menu">
                     <li><a data-edit="fontSize 5"><font size="5">Huge</font></a></li>
                     <li><a data-edit="fontSize 3"><font size="3">Normal</font></a></li>
                     <li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>
                  </ul>
               </div>
               <div class="btn-group">
                  <a class="btn btn-default" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="fa fa-bold"></i></a>
                  <a class="btn btn-default" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="fa fa-italic"></i></a>
                  <a class="btn btn-default" data-edit="strikethrough" title="Strikethrough"><i class="fa fa-strikethrough"></i></a>
                  <a class="btn btn-default" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="fa fa-underline"></i></a>
               </div>
               <div class="btn-group">
                  <a class="btn btn-default" data-edit="insertunorderedlist" title="Bullet list"><i class="fa fa-list-ul"></i></a>
                  <a class="btn btn-default" data-edit="insertorderedlist" title="Number list"><i class="fa fa-list-ol"></i></a>
                  <a class="btn btn-default" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="fa fa-outdent"></i></a>
                  <a class="btn btn-default" data-edit="indent" title="Indent (Tab)"><i class="fa fa-indent"></i></a>
               </div>
               <div class="btn-group">
                  <a class="btn btn-default" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="fa fa-align-left"></i></a>
                  <a class="btn btn-default" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="fa fa-align-center"></i></a>
                  <a class="btn btn-default" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="fa fa-align-right"></i></a>
                  <a class="btn btn-default" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="fa fa-align-justify"></i></a>
               </div>
               <div class="btn-group">
                  <a class="btn btn-default dropdown-toggle" data-toggle="dropdown" title="Hyperlink"><i class="fa fa-link"></i></a>
                  <div class="dropdown-menu input-append">
                     <input class="span2" placeholder="URL" type="text" data-edit="createLink"/>
                     <button class="btn btn-default" type="button">Add</button>
                  </div>
                  <a class="btn btn-default" data-edit="unlink" title="Remove Hyperlink"><i class="fa fa-scissors"></i></a>
               </div>
               <div class="btn-group">
                  <a class="btn btn-default" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="fa fa-picture-o"></i></a>
                  <input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
               </div>
               <div class="btn-group">
                  <a class="btn btn-default" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="fa fa-undo"></i></a>
                  <a class="btn btn-default" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="fa fa-repeat"></i></a>
               </div>
               <input type="text" data-edit="inserttext" id="voiceBtn" x-webkit-speech="">
            </div>
            <div id="editor">
               Write email here&hellip;
            </div>
         </div>
         <div class="emailComposeButtons">           
            <button class="btn btn-default">Discard Draft</button>
            <button class="btn btn-default"><i class="fa fa-paperclip"></i> Attach Files</button>
            <asp:LinkButton type="submit"  runat="server"   OnClick="Send_Click" ID="SendBtn"  CssClass="btn btn-info"><i class="fa fa-check-square-o"></i> Send</asp:LinkButton>
             <asp:LinkButton runat="server" OnClick="Unnamed_Click" ID="sdzs">sfsfsfsf</asp:LinkButton>
             <asp:Button ID="btn" OnClick="btn_Click" runat="server"/>
             <i class="fa fa-check-square-o" onclick=" document.getElementById('btn').click();"></i>
         </div></div>
      </form>
   </body>

</html>
  

C#

 protected void btn_Click(object sender, EventArgs e)
{
    BusinessLayer.EmailsController oEmailsController = new BusinessLayer.EmailsController();
    oEmailsController.Title = TextBoxTitle.Text;
    oEmailsController.PublishedDate = DateTime.Parse(TextBoxPublishDate.Text);
    oEmailsController.ExpiryDate = DateTime.Parse(TextBoxExpiryDate.Text);
    oEmailsController.FromGroupID = 1;
    string toIDs = TextBoxToIDs.Text;
    oEmailsController.FromID = Convert.ToInt32(System.Web.HttpContext.Current.User.Identity.Name.Split('$')[2]);
    oEmailsController.SendStatus = (int)Enumeration.EmailSendStatus.send;
    oEmailsController.ToLevelGroupID = (int)Enumeration.EmailSendStatus.send;
    Response.Redirect("inbox.aspx", false);
}

1 个答案:

答案 0 :(得分:0)

尝试替换href =“javascript:;” to href =“javascript:void(0);”在你的标签