Accessing client side dynamic controls within ASP.NET codebehind

前端 未结 3 1491
Happy的楠姐
Happy的楠姐 2021-01-20 00:11

Hi I\'m trying to access the html controls that are created dynamically within an event but I\'m unable to access this.

I\'m using the following code to create the

3条回答
  •  野的像风
    2021-01-20 00:28

    Well your adding client-side HTML controls via JavaScript - ASP.NET will not see those (they're not runat=server, this needs to be render-time, not after the page has loaded).

    What you can do is add "name" attributes to all your elements (which you've done), then when you submit the form (with the Button click), you can check the form elements via the Request.Form collection.

    protected void Button1_Click(object sender, EventArgs e)
    {
       var inputValue = Request.Form["someId"];
    }
    

    You might also need to set AutoPostBack="true" on the button, so it submits the form when you click the button.

    HTH

提交回复
热议问题