簡體   English   中英

如何在asp.net dotnetnuke c#中更改標簽的文本並將其顯示在頁面上?

[英]how to change text of label in asp.net dotnetnuke c# and display it on page?

我想在運行時使用標簽在頁面上顯示錯誤消息。

因此,我完成了以下類型的代碼。

protected void InsertButton_Click(object sender, EventArgs e)
{
    //this.FormView1.Visible = false;
    //LinkButton1.Text = "Update Successful - Add Another Page";
    TextBox txtauthor = this.FormView1.FindControl("txtPageAuthor") as TextBox;
    TextBox txttitle = this.FormView1.FindControl("txtPageTitle") as TextBox;
    TextBox txttag = this.FormView1.FindControl("txtTagName") as TextBox;
    Label lblAuthor = this.FormView1.FindControl("lblAuthor") as Label;
    Label lblTitle = this.FormView1.FindControl("lblTitle") as Label;
    Label lblTag = this.FormView1.FindControl("lblTag") as Label;

    if (string.IsNullOrEmpty(txtauthor.Text))
    {
        lblAuthor.Text = "Author Name must be entered";
        valid = 1;
    }
    if (string.IsNullOrEmpty(txttitle.Text))
    {
        lblTitle.Text = "Page Title must be entered";
        valid = 1;
    }
    if (string.IsNullOrEmpty(txttag.Text))
    {
        lblTag.Text = "Tag Name must be entered";
        valid = 1;
    }
    Page_Load(sender, e);
    this.GridView1.DataBind();
}

// Page Load Event

public void Page_Load(object sender, EventArgs e)
{
    Label lblAuthor = this.FormView1.FindControl("lblAuthor") as Label;
    Label lblTitle = this.FormView1.FindControl("lblTitle") as Label;
    Label lblTag = this.FormView1.FindControl("lblTag") as Label;

    if (Page.IsPostBack)
    {
        //if (valid != 0)
        //{
        lblAuthor.Text = "Author Name must be entered";
        lblTitle.Text = "Page Title must be entered";
        lblTag.Text = "Tag Name must be entered";
        //}
    }
}

下面我提到了我的InsertButton的aspx代碼:

<div class="lineheight">
                <p style="display: inline; float: left; width: 100%">
                    <asp:Label ID="lblBlank" runat="server" Text="&nbsp" Width="100px" Style="float: left;"></asp:Label>
                    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                        Text="Add Page" CssClass="btn" onclick="InsertButton_Click" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                        CommandName="Cancel" Text="Cancel"  CssClass="btn" 
                        onclick="InsertCancelButton_Click" />
    </p>
    </div>

但是,每當我單擊添加按鈕時,整個頁面都會重定向,並且標簽的默認值即“”(空白)會打印在頁面上。

我們歡迎所有答案。

提前致謝..

您可以使用ASP驗證器 它們既好又簡單,您也可以創建自定義驗證器。 這是鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM