简体   繁体   English

在asp.net的Ajax更新面板中使用Jquery JqTransform插件时出现问题

[英]Issue While using an Jquery JqTransform plugin within Ajax update panel in asp.net

I am facing an issue while using a Jquery JqTransform plugin with controls inside an Ajax update panel in asp.net. 在将Jquery JqTransform插件与asp.net中的Ajax更新面板内的控件一起使用时,我遇到问题。 Here is the code: 这是代码:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true"></asp:ToolkitScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
      <asp:DropDownList ID="ddlArtist" runat="server" AutoPostBack="True" onselectedindexchanged="ddlArtist_SelectedIndexChanged"></asp:DropDownList>
      <p class="maintext"><asp:Literal ID="ltrArtistDesc" runat="server"></asp:Literal></p>
    </ContentTemplate>

    <Triggers>
       <asp:AsyncPostBackTrigger ControlID="ddlArtist" EventName="SelectedIndexChanged" />
    </Triggers>

</asp:UpdatePanel>

when the Page loads it applies jqtransform to convert the dropdown and other Controls and apply some style. 当页面加载时,它将应用jqtransform来转换下拉菜单和其他控件并应用某种样式。 But as soon as I select an Album from the dropdownlist it does a postback and retrieves further details from the database. 但是,一旦我从下拉列表中选择一个专辑,它就会回发并从数据库中检索更多详细信息。 To avoid that full postback I am using an update panel. 为了避免全部回发,我正在使用更新面板。 But after using it I started facing the problem "my controls on the page aren't converted by the jqtransform". 但是在使用它之后,我开始面对“我的页面上的控件没有被jqtransform转换”的问题。

In the page head there is a script, the file that calls the JqTransform. 在页面标题中,有一个脚本,该文件称为JqTransform。 Here it is: 这里是:

<script language="javascript" type="text/javascript">
        $(function(){
            $('form').jqTransform({imgPath:'jqtransformplugin/img/'});
        });
</script>

Please help me i just want that jqTransform will be applied to controls even if i select an album from the dropdownlist and it causes a partial postback. 请帮助我,即使我从下拉列表中选择一个相册,它也会导致部分回发,我只是希望jqTransform将应用于控件。

In case of a Microsoft Update Panel 如果是Microsoft更新面板

$(document).ready(function () {
        var prm = Sys.WebForms.PageRequestManager.getInstance();

     prm.add_endRequest(EndRequest);

     function EndRequest(sender, args) {

             $('form.jqtransform').removeClass('jqtransformdone');
             $('form.jqtransform').removeClass('jqTransformHidden');

                    $("form.jqtransform").jqTransform({ selectwidth: 240 });
            }
});

Create a new div inside the <ContentTemplate> and call jqTransform plugin for that div. <ContentTemplate>内创建一个新的div,然后为该div调用jqTransform插件。

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <div class="formstyle">
        ......... Your form elements
    </div>
    </ContentTemplate>
</asp:UpdatePanel>

and then call jqTransform plugin as below: 然后按如下所示调用jqTransform插件:

<script type="text/javascript">
  $(function () {
    //Initial bind
    $(document).ready(function () {
      BindControlEvents();

      //Re-bind for callbacks
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      prm.add_endRequest(function () {
        BindControlEvents();
      });

      function BindControlEvents() {
        $('.formstyle').jqTransform();
      }
    });
  });
</script>

jqTransform worked fine for me even after getting postbacks through the updatepanel. 即使在通过updatepanel获得回发之后,jqTransform对我来说也能正常工作。

If you want to call your jquery method on every postback then you need to have an Ajax pageLoad, not just on document ready. 如果要在每次回发中调用jquery方法,则需要具有Ajax pageLoad,而不仅仅是准备好文档。 To get jqTransform working on pageLoad use the following: 要使jqTransform在pageLoad上运行,请使用以下命令:

<script type="text/javascript">

    function pageLoad() {
        $("form").removeClass("jqtransformdone");
        $("form").jqTransform(); 
    };

</script>

I've had this situation before, its not an issue its by design. 我以前遇到过这种情况,这不是设计问题。 What you are doing is reloading a new list into a combobox effectively destroying whats already rendered. 您正在做的是将一个新列表重新加载到组合框中,从而有效地破坏了已呈现的内容。 Sounds like the partial postback is an ajax call so for example if your ajax function looked like this 听起来部分回发是ajax调用,因此例如您的ajax函数看起来像这样

$.ajax({
url: 'ajax/updatelist.html',
  success: function(data) {
      ...your code to update list...then
      $('form').jqTransform({imgPath:'jqtransformplugin/img/'}); //this will re render your form!
   }
});

You could even go ahead and just re-jqTransform the combo box if thats then only item being updated instead of the whole form for performance. 您甚至可以继续进行操作,如果只更新项目而不是整个表单来提高性能,则只需重新jqTransform组合框即可。 Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM