Reputation: 27723
I am trying to get CLientID inside the .ascx (user control mark-up) file.
While this
My id is: <%=this.ClientID%>
renders as My id is: fracTemplateCtrl
This:
<asp:Button ID="btnSave" runat="server" Text="Save Template" onclick="btnSave_Click" OnClientClick="return confirmSave('<%=this.ClientID%>');" />
renders as (inside Source code):
<input type="submit" name="fracTemplateCtrl$btnSave" value="Save Template" onclick="return confirmSave('<%=this.ClientID%>');" id="fracTemplateCtrl_btnSave" />
Clearly, ClientId property does not get evaluated in the second case. How do I overcome this issue? (aside from hardcoding, which is not the answer, I would like to make the user control independent)
Upvotes: 2
Views: 5077
Reputation: 13031
Try this instead
<asp:Button ID="btnSave" runat="server" Text="Save Template" onclick="btnSave_Click" OnClientClick="return confirmSave(this.id);" />
Upvotes: 2
Reputation: 15196
You could set the OnClientClick property's value server-side like this:
btnSave.OnClientClick = "return confirmSave('" + this.ClientID + "')";
Upvotes: 3