繁体   English   中英

ASP.NET标签为空

[英]ASP.NET label is null

我正在尝试使用C#创建一个网站。 我有一个主页,有一个DevExpress DateEdit,4个DevExpress DropDownLists,一个按钮和一个标签。 我有一个这样的方法:

protected void dropdownNolar_SelectedIndexChanged(object sender, EventArgs e)
{
    var halisaha = (from veri in veriler.tum_halisahalars
                    where veri.Il == dropdownIl.Text &&
                     veri.Ilce == dropdownIlce.Text &&
                    veri.Mahalle == dropdownMahalle.Text &&
                    veri.No == dropdownNolar.Text
                    select veri).FirstOrDefault();

    if (halisaha != null)
        if (halisaha.description != null)
            lblDescription.Text = halisaha.description;
}

和母版页的aspx代码:

<%@ Master Language="C#" AutoEventWireup="true" EnableViewState="true" CodeBehind="~/masterPage.master.cs" Inherits="HaliSahaKiralama.masterPage" %>

<%@ Register assembly="DevExpress.Web.v14.1, Version=14.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head id="Head1" runat="server">
<title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="Web Page Maker">
<style type="text/css">
    #wrapper {
    position:relative;
    width: 1127px;
    margin-top: 20px;
    margin-left: auto;
    margin-right: auto;
    text-align:left;
        top: -2px;
        left: 55px;
        height: 1000px;
        background-color:sandybrown;
    }
    .auto-style1 {
        width: 100%;
        height: 912px;
        border: 5px solid #FFFFFF;
        background-color: #66FF33;
    }
    .auto-style2 {
        height: 792px;
    }
    .auto-style4 {
        height: 130px;
        border:thick none white;
        }
    .auto-style5 {
        height: 792px;
        width: 237px;
    }
</style>
</head>
<body style="margin:0px; height: 1093px; background-color:sandybrown" onload="">
    <script type="text/javascript" language="javascript">
    </script>
    <form id="form1" runat="server">
<div id="wrapper">
    <table class="auto-style1">
        <tr>
            <td class="auto-style4" colspan="2" style="background-color:lightseagreen">&nbsp;&nbsp;
                <div style="border-style: none; border-color: inherit; border-width: thick; z-index: 1; left: 8px; top: 9px; position: absolute; height: 130px; width: 1111px;">
                <img src="hs2.jpg" style="position:absolute; top: 6px; left: 33px; width: 157px;" alt="" />
                <dx:ASPxLabel ID="ASPxLabel6" runat="server" Font-Size="36pt" style="z-index: 1; left: 226px; top: 31px; position: absolute; height: 82px; width: 505px" Text="Bamyac&#305;lar Hal&#305;saha" Theme="Youthful">
                </dx:ASPxLabel>
                    </div>
            </td>

        </tr>
        <tr>
            <td class="auto-style5" style="background-color:darkgreen">
                <div style="position:absolute; top: -13px; left: 8px; width: 236px; height: 639px; background-color:transparent">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
                <dx:ASPxDateEdit ID="date_editTarih" runat="server" Date="2015-03-24" Font-Size="16pt" style="z-index: 1; left: 18px; top: 196px; position: absolute; height: 21px; width: 170px" Theme="Youthful">
                </dx:ASPxDateEdit>
                <dx:ASPxLabel ID="ASPxLabel1" runat="server" Font-Size="12pt" style="z-index: 1; left: 18px; top: 165px; position: absolute" Text="&#304;stedi&#287;iniz Tarihi Seçiniz:" Theme="Youthful" ForeColor="White">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="dropdownIl" runat="server" style="z-index: 1; left: 18px; top: 280px; position: absolute; height: 29px; width: 170px" Theme="Youthful" OnSelectedIndexChanged="dropdownIl_SelectedIndexChanged1" NullText="&#304;l Seçiniz!">
                </dx:ASPxComboBox>
                <dx:ASPxLabel ID="ASPxLabel2" runat="server" Font-Size="12pt" style="z-index: 1; left: 18px; top: 478px; position: absolute" Text="Stat Numaras&#305;n&#305; Seçiniz:" Theme="Youthful" ForeColor="White">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="dropdownIlce" runat="server" style="z-index: 1; left: 17px; top: 353px; position: absolute; height: 29px; width: 170px; bottom: 727px;" Theme="Youthful" OnSelectedIndexChanged="dropdownIlce_SelectedIndexChanged1" NullText="&#304;lçe Seçiniz! ">
                </dx:ASPxComboBox>
                <dx:ASPxLabel ID="ASPxLabel3" runat="server" Font-Size="12pt" style="z-index: 1; left: 18px; top: 249px; position: absolute" Text="&#304;linizi Seçiniz:" Theme="Youthful" ForeColor="White">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="dropdownMahalle" runat="server" style="z-index: 1; left: 17px; top: 431px; position: absolute; height: 29px; width: 170px" Theme="Youthful" OnSelectedIndexChanged="dropdownMahalle_SelectedIndexChanged1" NullText="Mahalle Seçiniz! ">
                </dx:ASPxComboBox>
                <dx:ASPxLabel ID="ASPxLabel4" runat="server" Font-Size="12pt" style="z-index: 1; left: 18px; top: 322px; position: absolute" Text="&#304;lçenizi Seçiniz:" Theme="Youthful" ForeColor="White">
                </dx:ASPxLabel>
                <dx:ASPxComboBox ID="dropdownNolar" runat="server" style="z-index: 1; left: 18px; top: 510px; position: absolute; height: 29px; width: 170px" Theme="Youthful" OnSelectedIndexChanged="dropdownNolar_SelectedIndexChanged" NullText="Numara Seçiniz!">
                </dx:ASPxComboBox>
                <dx:ASPxLabel ID="ASPxLabel5" runat="server" Font-Size="12pt" style="z-index: 1; left: 18px; top: 400px; position: absolute" Text="Mahallenizi Seçiniz:" Theme="Youthful" ForeColor="White">
                </dx:ASPxLabel>
                    <dx:ASPxButton ID="BtnMasterPageDevamEt" runat="server" Font-Size="12pt" style="z-index: 1; left: 18px; top: 555px; position: absolute" Text="Devam Et" Theme="PlasticBlue" OnClick="btnClickEski01">
                            </dx:ASPxButton>
                    </asp:ContentPlaceHolder>
                    </div>
                <br />
            </td>
            <td class="auto-style2">
                <div style="z-index: 1; left: 257px; top: 144px; position: absolute; height: 784px; width: 862px;background-color:#9ACD32">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                        <p>
                            <br />
                        </p>
                        <p>
                            &nbsp;</p>
                        <p>
                        </p>
                        <p>
                            <dx:ASPxBinaryImage ID="ASPxBinaryImage1" runat="server" style="z-index: 1; left: -237px; top: 443px; position: absolute; height: 109px; width: 155px">
                            </dx:ASPxBinaryImage>
                        </p>
                        <p>
                        </p>
                        <p>

                        </p>
                        <p>
                            &nbsp;</p>
                        <p>
                        </p>
                        <p>
                        </p>
                        <p>
                        </p>
                        <p>
                        </p>
                        <p>
                        </p>
                        <p>
                        </p>
                        <p>

                            &nbsp;</p>
                        <p style="margin-left: 0px">
                        </p>
                            <asp:Label ID="lblDescription" runat="server" ForeColor="White" Font-Names="Comic Sans MS" style="z-index: 1; left: -226px; top: 583px; position: absolute; height: 14px" Text="Açıklama">
                            </asp:Label>
                        <p>
                        </p>
                        <p>
                            &nbsp;</p>
                        <p>
                        </p>
                    </asp:ContentPlaceHolder>
                </div>
            </td>
        </tr>
    </table>
</div>
    </form>
</body>
</html>

DropDownLists不为null,但我的标签为null。 为什么会发生?

查看您的代码示例。 您正处于“回发事件处理”阶段。 在那个阶段,所有控件应准备就绪。

问题是什么可能导致这种意外行为以及如何找出问题? 这是MasterPage运行时行为:

  1. 用户通过键入内容页面(.aspx页面)的URL请求页面
  2. 提取页面后,将读取@ Page指令。 如果指令引用了母版页,则也会读取母版页。 如果这是第一次请求页面,则将同时编译两个页面。
  3. 具有更新内容的母版页将合并到内容页的控制树中。
  4. 单个Content控件的内容将合并到母版页中相应的ContentPlaceHolder控件中-换句话说,.aspx页中的Content控件将替换MasterPage中的占位符内容。
  5. 生成的合并页面将呈现给浏览器。

问题是该流程出了什么问题。 为什么将MasterPage中的控件设置为null? *您已在MasterPage上的占位符内添加了代码,这些代码将被Content控件替换,并可能以空值结尾。

希望对您有帮助。

暂无
暂无

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

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