0

こんにちは。asp.net の別の div 内に新しい div を作成しました。今度は、新しく作成された div の innerhtml プロパティを使用したいと思います。私は方法を見つけることができません..

これは、私の .aspx ページで行っていることです。

      <asp:ScriptManager ID="ScriptManager1" runat="server">
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div id="forNewEmployee" runat="server"></div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="link" EventName="click" />
        </Triggers>
      </asp:UpdatePanel>

     <div class="addMore">
      <asp:Button ID="link"  CssClass="label"  runat="server" Text="Add More - Image" 
          onclick="link_Click" />
     </div>   

そしてコードビハインドファイルで..

protected void link_Click(object sender, EventArgs e)
{
    if (clickCheck != 0)
    {
        // access the newly generated div 'forNewEmployee' + specific id and call its innerHtml Method?
        System.Web.UI.HtmlControls.HtmlControl div = (System.Web.UI.HtmlControls.HtmlControl)ScriptManager1.FindControl("forNewEmployee" + clickCheck);

    }
    else {
        this.forNewEmployee.InnerHtml = newRow();        
    }
}

forNewEmployee div内に新しい要素を導入するための文字列を作成する関数があります。このように定義されています..

protected string newRow() {
    // check for click
    clickCheck++;

    // check for new row
    countForEmployee++;

    // building our new row
    rowString.AppendLine("<label for='empName" + countForEmployee.ToString() + "'>Your Employee Name: <span>(required)</span></label>");
    rowString.AppendLine("<input id='empName" + countForEmployee.ToString() + "' class='registrationformEmployeeText' />");
    rowString.AppendLine("</div>");

    rowString.AppendLine("<div id='forNewEmployee" + countForEmployee.ToString() + "' name='forNewEmployee" + countForEmployee.ToString() + "' runat='server'></div>");

    return rowString.ToString();
}
4

2 に答える 2

0

最も簡単な方法は、asp .net パネルを使用して、asp .net コントロールを作成および追加することです (リテラル コントロールであっても)。

したがって、基本的に NewRow 関数は次のようになります。

protected Panel newRow() { 
   // check for click 
   clickCheck++; 

   // check for new row 
   countForEmployee++; 

   // building our new row 
    Panel pnl = new Panel();
    pnl.Controls.Add(new Literal("<label for='empName" + countForEmployee.ToString() + "'>Your Employee    Name: <span>(required)</span></label>"));
    pnl.Controls.Add(new Literal("<input id='empName" + countForEmployee.ToString() + "' class='registrationformEmployeeText' />"));

    Panel forNewEmployee = new Panel();
    forNewEmployee.ID = "forNewEmployee" + countForEmployee.ToString();

    pnl.Controls.Add(forNewEmployee);

    return pnl;

} 

このようにして、指定したコントロール ID で FindControl を実行できるようになります。

于 2012-01-20T16:51:55.293 に答える
0

私はあなたがそれを行うことができるかどうか完全にはわかりませんが、あなたがそれをdiv行うことができると確信していますasp:Panel:

this.forNewEmployee.Controls.Add(new Literal(newRow());
于 2012-01-20T14:46:31.583 に答える