How to use a javascript variable in the OnClientClick attribute of a ASP.NET control -


i have single textbox txtuser user can input username, , there delete button beside textbox. providing delete confirmation using onclientclick attribute of <asp:button>.

the message is: are sure want delete user? works.

i want change message are sure want delete 'username'? getting value of username textbox using getelementbyid("<%= txtuser.clientid %>") , storing in variable user

<script type="text/javascript"> var username = document.getelementbyid(<%= txtuser.clientid %>") </script> 

now want use username variable in onclientclick call. tried this, didn't work:

    <asp:button id="btndelete" runat="server"  onclientclick="return confirm('are sure want delete "+username+"');"> delete</asp:button> 

almost there...

<script type="text/javascript"> var username = document.getelementbyid("<%= txtuser.clientid %>").value; </script> 

then

<asp:button id="btndelete" runat="server" onclientclick="return confirm('are sure want delete '+username+'?');">delete</asp:button> 

should it. need value of text box, , append username sure string, not append asp control.

as word of possible warning, if attempt value of textbox , assign username before textbox rendered, result in error. make sure assignment of username after textbox in markup, or use window.onload.


Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -