English 中文(简体)
动态内容w/jQuery
原标题:Dynamic content w/ jQuery

我刚刚开始学习jQuery,并希望将内容从一个单独的.aspx页面动态加载到div中http://www.asp.net/ajaxLibrary/jquery_webforms_dynamic_load.ashx?HL=var“rel=”nofollow“>http://www.asp.net/ajaxLibrary/jquery_webforms_dynamic_load.ashx?HL=var。

然而,它似乎没有回应,我可能错过了其中的一部分。以下是我的.aspx页面中的代码/脚本:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script src="Scripts/jquery-1.5.js" type="text/javascript"></script>       
<script type="text/javascript">

$(document).ready(function () {
    // External ASPX Page calling   
    $("#btn_Submit").click(loadDynamic);
});

function loadDynamic() {

    $("#dynamicResults").load("ResultsView.aspx", 
        {name: $("#cbox_User").val() },  
        function (content) {   
           $(this).hide().fadeIn("slow");
                return false;
        });
}  

<Header>
QUERY VIEW
</Header>

<Content>
    <div style="float:right; height:154px; width: 947px; margin-left: 0px; background-color: #E0E0E0;">
        <br />
        <asp:Label ID="Label2" runat="server" Text="Select a User:" 
                    Style="margin-left:28px" ></asp:Label>

                    <asp:ComboBox ID="cbox_User" runat="server" AutoCompleteMode="SuggestAppend">
                    </asp:ComboBox>

                <asp:Label ID="Label3" runat="server" Text="Select a Month:" 
                                Style="margin-left:28px" ></asp:Label>
            <asp:TextBox ID="txt_Date" runat="server"></asp:TextBox>
                <asp:CalendarExtender ID="CalendarExtender1" runat="server" 
                            TargetControlID="txt_Date" 
                            Format="MMMM yyyy" 
                            OnClientShown="onCalendarShown"
                            OnClientHidden="onCalendarHidden"
                            BehaviorID="calendar1" >
                </asp:CalendarExtender>
                <asp:Button ID="btn_Submit" runat="server" Text="Submit" Style="margin-left:28px" onclick="Btn_Submit_Click" />
</div>
</Content>


<Header>
RESULTS VIEW
</Header>

<Content>
    <div id="dynamicResults">
    </div>
    <div style="border-style: none; height:340px; width: 770px; position:relative; top: 10px; left: -2px;">
     <asp:GridView ID="ResultsView" runat="server" CellPadding="3" 
         ForeColor="Black" GridLines="None" AllowPaging="False" 
         Visible="False" 
         Height="318px" style="margin-left: 32px; margin-top: 2px;" Width="718px" 
         BackColor="White" BorderColor="#999999" BorderStyle="Solid" 
         BorderWidth="1px">
        </asp:GridView>
     </div>
</Content>

在第二个.aspx页面中,我只想动态加载一个div:

<html xmlns="http://www.w3.org/1999/xhtml">
   <div style="background-color:#E0E0E0; border-style: ridge none none none; border-        width: thin; border-color: #B3B3B3; height:120px; width: 770px;  position:relative;     top: 10px; left: 8px;">
          <asp:Label ID="lbl_Header" runat="server" Text="User  Information:"></asp:Label>
   </div> 
 </html>
最佳回答

查看加载方法。

以下是页面中的一个示例:

Loading Page Fragments The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. This is achieved with a special syntax for the url parameter. If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded.

We could modify the example above to use only part of the document that is fetched:

$( #result ).load( ajax/test.html #container );

When this method executes, it retrieves the content of ajax/test.html, but then jQuery parses the returned document to find the element with an ID of container. This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.

jQuery uses the browser s .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as , , or elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

编辑:刚刚注意到,在您的函数loadDynamic()中,您正试图获得控件cbox_User的值,如下所示:

$("#cbox_User").val()

但是,因为它是一个服务器端控件,您需要获得如下值:

$("#<%=cbox_User.ClientID%.").val()

这是因为.NET为ASP.NET控件提供的id与您指定的id不同。

希望这能有所帮助。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签