I have a User Control in which I have one label.
<asp:Label ID="lblProductionName"
runat="server"
Text="Production Name will come here">
</asp:Label>
I render the given UC from code behind using this function:
private string RenderControl(Control control)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter writer = new HtmlTextWriter(sw);
control.RenderControl(writer);
return sb.ToString();
}
After rendering, I get this as the output string:
<span id="lblProductionName">Production Name will come here</span>
Now, when I put two instances of the same User Control, I get the same span ID in the output string.
I want to generate two different IDs for two instances of User Control. How can I generate it?
Sometimes called time-based UUIDs, these IDs are generated using a combination of datetime values (reflecting the time the UUID is being generated), a random value, and a part of the MAC address of the device generating the UUID.
The UniqueID property is the page-wide unique identifier of an ASP.NET server control. Its uniqueness is guaranteed by prefixing the ID of a server control with the ID of its NamingContainer. If the NamingContainer is the Page the UniqueID will remain the same as the ID.
The option which always works would be: Guid.NewGuid :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With