At runtime, does the Form ID Asp.net webforms change?

Asked

Viewed 85 times

1

At runtime, the Form ID Asp.net webforms changes, see that I have on my machine the component ID.

Local example:

 <asp:HiddenField runat="server"  ID="MenuSelecionado" value="processo"/>

After execution it looks like this:

<input type="hidden" name="ctl00$ContentPlaceHolder1$MenuSelecionado" id="ctl00_ContentPlaceHolder1_MenuSelecionado" value="processo">

I wonder if you have any way to keep the ID or use other property in his stead.

1 answer

1

Yes, you can use the ClientIDMode

<asp:HiddenField runat="server"  ID="MenuSelecionado" value="processo" ClientIDMode="Static"/>

You can see more about him in documentation

Alternative:

Keep it that way:

<asp:HiddenField runat="server" ID="MenuSelecionado" Value="processo" />

And on Page_load:

MenuSelecionado.ID = "MenuSelecionado";

The problem this way is that it will add the text "Maincontent" before, thus getting the element

<input name="ctl00$MainContent$Bla" id="MainContent_MenuSelecionado" value="processo" type="hidden">

I’ll run some tests if I can find another way

  • Thanks for the help, but it did not work,The type 'System.Web.UI.WebControls.Hiddenfield' does not have a public property called 'Clientidmode'.

  • Strange not work, maybe it’s version, I did a test here and was. Anyway I added another alternative

  • Cannot use Clientidmode="Static", does not work

Browser other questions tagged

You are not signed in. Login or sign up in order to post.