c# - Not able to append string in ScriptManager.RegisterStartupScript's alert -


i want show alert on click event of button in aspx page in want display name of user logged in.

i trying using scriptmanager.registerstartupscript in following way found here :

scriptmanager.registerstartupscript(lnkbtnsavecart, lnkbtnsavecart.gettype(), "key", string.format("alert(mr/ms.'{0}' , cart saved successfully!);",customerobj.name ), true); 

i have put break points see if customerobj contains name property or not , had necessary name of logged-in user.

this way works though , dont need :

scriptmanager.registerstartupscript(lnkbtnsavecart, lnkbtnsavecart.gettype(), "key", "alert('some message!')", true); 

the single quotes in alert message incorrect. content within alert function should in single quotes. if need single quotes around name have escape it. try this

scriptmanager.registerstartupscript(lnkbtnsavecart, lnkbtnsavecart.gettype(), "key", string.format("alert('mr/ms. {0} , cart saved successfully!');",customerobj.name ), true); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -