使用Ajax时无法刷新Menuitem中当前选择的项目 [英] Lable not refreshing to current selected item in Menuitem while using Ajax

查看:121
本文介绍了使用Ajax时无法刷新Menuitem中当前选择的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了updatepanel的问题.
我正在使用ASP菜单控件.我在UpdatePanel中有一个标签控件.
单击菜单后,我选择了selectedvalue并显示为标签文本.我的代码有效,但是每当我单击时,我都会在标签中得到先前选择的值,而不是最新的.

例如:我的菜单中有Item1,Item2,Item3和Item4

加载后,单击"Item1",标签不会刷新.
然后这次我单击Item3,标签会刷新,但会显示以前选择的值,即Item1.
然后,这次我单击Item2,标签刷新,但再次显示先前选择的值,即:Item3.:mad:X |.

以下是我的aspx代码

I am facing a problem with the updatepanel.
I am using a ASP menu control. I have a lable control within an UpdatePanel.
Upon clicking the menu , I pick the selectedvalue and display as lable text. My code works but whenever I click I get the previously selected value in the lable and not the latest one.

For ex:I have Item1,Item2,Item3 and Item4 in my menu

Upon loading I click Item1 the lable does not refresh.
Then I click on Item3 this time the lable refreshes but shows the previously selected value i.e:Item1.
Then I click on Item2 this time the lable refreshes but again shows the previously selected value i.e:Item3.:mad: X|

Below is my aspx code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Menu ID="Menu1" runat="server">
            <Items>
                <asp:MenuItem Text="Item1" Value="Item1"></asp:MenuItem>
                <asp:MenuItem Text="Item2" Value="Item2"></asp:MenuItem>
                <asp:MenuItem Text="Item3" Value="Item3"></asp:MenuItem>
                <asp:MenuItem Text="Item4" Value="Item4"></asp:MenuItem>
            </Items>
        </asp:Menu>
        
         <asp:ScriptManager ID="ScriptManager1" 
                   runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" 
                 UpdateMode="Conditional"
                 runat="server">
                 <Triggers>
                   <asp:AsyncPostBackTrigger ControlID="Menu1" />
                 </Triggers>
                 <ContentTemplate>
                 <fieldset>
                 <asp:Label ID="Label1" runat="server" 
                            ForeColor="White" Font-Size="Large" BackColor="#00447b" Width="700px" ></asp:Label>
                 </fieldset>
                 </ContentTemplate>
</asp:UpdatePanel>
    
    </div>
    </form>
</body>
</html>



这是我背后的代码



this is my code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Menu1.SelectedItem != null)
            Label1.Text = Menu1.SelectedValue;
    }
}




请为此提供一些帮助.




Please provide me some help on this.

推荐答案

您的菜单不在更新面板内.我相信这将不会在AJAX调用中对其进行更新.它显示前一项的事实意味着它的呈现,然后更新状态,而不是相反.
Your menu is not inside your update panel. I believe that means it won''t be updated in the AJAX call. The fact that it shows the previous item means that it''s rendering, THEN updating the state, instead of vice versa.


这篇关于使用Ajax时无法刷新Menuitem中当前选择的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆