简体   繁体   English

在ASPX页面上动态加载数据

[英]Dynamic data load on ASPX page

I have an internal web service (ASP.NET) written on C# in a company I work for. 我在一家工作的公司中使用C#编写了一个内部Web服务(ASP.NET)。 There are only 2 pages in it, one of this pages contains DropDownList. 其中只有2页,其中一页包含DropDownList。 Every time when user selecting an item from that DropDownList I need to somehow pass selected item value to a static method and show result string of that method anywhere on page. 每次用户从DropDownList中选择一个项目时,我都需要以某种方式将所选项目的值传递给静态方法,并在页面上的任何位置显示该方法的结果字符串。

I've never worked with ASP.NET or any web programming before and a bit confused about how to do it, not sure where to start looking even. 我以前从未使用过ASP.NET或任何Web编程,并且对如何操作有些困惑,不确定从哪里开始寻找。

In your aspx file you should have this: 在您的aspx文件中,您应该具有以下内容:

 <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" 
            onselectedindexchanged="ListBox1_SelectedIndexChanged"></asp:ListBox>

Notice the AutoPostBack="True" which goes back to the server and fires the selectedindexchanged event immediately after the user changes the selection in the listbox 请注意AutoPostBack =“ True” ,它会返回到服务器并在用户更改列表框中的选择后立即触发selectedindexchanged事件

In your code-behind (.cs file) You should have this: 在您的代码隐藏文件(.cs文件)中,您应该具有以下代码:

 protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

        // Call static method and pass the ListBox1.SelectedIndex
        // MyStaticMethod(ListBox1.SelectedIndex);
    }

您可以设置autoPostBack =“ true”并在服务器端处理更改事件,或者使用jQuery订阅更改事件并在客户端获取值

You should probably check out some of the great resources that microsoft provides for new .NET developers. 您可能应该检查一下Microsoft为新的.NET开发人员提供的一些很棒的资源。 They will be really helpful in getting you started. 他们对于您入门很有帮助。 Her is a link of some really good videos to help you out: http://www.asp.net/web-forms/videos 她是一些非常好的视频的链接,可以帮助您: http : //www.asp.net/web-forms/videos

Not sure what language you are coming from, if any... But for the most part webforms is going to work a lot like other web based methodologies. 不知道您来自哪种语言,如果有的话...但是大多数情况下,Web表单会像其他基于Web的方法一样工作。

Your ASP.NET Controls (in your case the DropDownList) have both client and server side events. 您的ASP.NET控件(在您的情况下为DropDownList)具有客户端和服务器端事件。

You will probably want to map the server-side OnSelectedIndexChanged event on your DropDownList. 您可能需要在DropDownList上映射服务器端OnSelectedIndexChanged事件。

In order to cause a postback on that control you will want to set the AutoPostBack property to true on your DropDownList. 为了在该控件上引起回发,您将需要在DropDownList上将AutoPostBack属性设置为true。

try this one 试试这个

In html , 在html中,

        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>

In aspx.cs page,, 在aspx.cs页面中,

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    string selctedValue = DropDownList1.SelectedValue;
        /// Call yours static methid here
     YourMethod(selctedValue);
}

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

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