how to embed javascript in the ASP.net

G

Green

Hi,
I have the following method in the WebUI class as following:

public void Confirm(System.Web.UI.Page parentObject,string message){
StringBuilder sb = new StringBuilder();

sb.Append("<script language=Javascript >");
sb.Append("confirm('"+message+"');");
sb.Append("</script>");

if(!parentObject.IsStartupScriptRegistered("ConfirmScript"))
parentObject.RegisterStartupScript("ConfirmScript",sb.ToString());
}

And in the code-behind of the aspx page in have:
WebUI ui = new WebUI();
ui.Alert(Page,"The document already exists.");

But it does not fire up(no alert pop up!)

Do you have any ideas?

Thx in advance.
 
S

Steven Cheng[MSFT]

Hi Green,

From your description, you used a helper class to register some client
scripts in your asp.net page(calling the Page.RegisterStartupScript) ,but
find the registered script not work, yes?

I'm not sure the detailed code logic in your asp.net page. Where did you
call your helper function, the
"ui.Alert"? From my local test, it works well when I just use a helper
class to register startup script in the page's button_click post back
event. I think you can first try directly use the
Page.RegisterStartupScript in your page instead of using the helper class ,
also test in a simple empty page( get rid of the other potential issues) to
see whether the problem still occurs.
In addittion, if you feel it convenient that provide the detailed code of
your problem page here, we can do some further troubleshoot on our side.

Please feel free to post here if you have any questions. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top