473,473 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to embed javascript in the ASP.net

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("Confir mScript"))
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.
Nov 18 '05 #1
2 1502
I think you need to load the client-side script each time:

http://www.ftponline.com/vsm/2002_07...net/page3.aspx
"Green" wrote:
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("Confir mScript"))
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.

Nov 18 '05 #2
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.)

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: chaitatp | last post by:
Hi guys, I have posted a similar question before but this post has some different. The similar link is: ...
3
by: abrtlt | last post by:
I would like to have a web page in which, when the user clicks on any of several specific elements, a specific audio file is played, without reloading the page. The specific audio file name is...
2
polymorphic
by: polymorphic | last post by:
I am no longer good at Javascript and need help. I'm trying to embed pdf files in html then build some sort of navigation between the pdfs via the pdf numbered file name. I can generate the...
13
by: windsorben | last post by:
I have some javascript that checks whether or not an answer is correct. It was working fine when the question was asked with text but now that I'm asking the question with audio, the javascript no...
3
by: helraizer1 | last post by:
I have this code in JS function show_player() { document.mediaplayer1.style.visibility = "visible"; } function content(p, clip) { var mus = document.getElementById('music'); ...
5
by: elbin | last post by:
Hello, first to say that I am a total beginner in Javascript but I know some programming (python in particular) and am able to understand methods/parameters and so on. Here's my problem: I am...
1
by: ShahzadMahmood | last post by:
I want to embed the following code in javascript function javascript function is written just after the object code, I want to replace the popup window code with this object code while the file name...
2
dream party
by: dream party | last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.