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
Post a Comment