Client Side Scripts

A

Arfin

Any Response.Write("Something") that I put on the Page_Load of a Web
User Control gets "printed" on the page before the first <html> tag.

How can I programmatically add some html scripts to a control without
using the Page_Load?

On the same line. Is there a way from the [MyControl].ascx (the html)
to access variables created in the [MyControl].ascx.vb (the code)?
 
D

Drew Robbins

Use Page.RegisterClientScriptBlock to add script to the output of the
page. You can also call Page.IsClientScriptBlockRegistered to prevent
registering the script twice.

You can expose your fields/variables as Protected properties and access
them from the ASCX file.
 
S

Scott Mitchell [MVP]

Arfin said:
Any Response.Write("Something") that I put on the Page_Load of a Web
User Control gets "printed" on the page before the first <html> tag.

How can I programmatically add some html scripts to a control without
using the Page_Load?

If you want to *programmatically* add script, you're going to have to do
it somewhere in the code-behind class. There are methods in the Page
class to assist with injecting client-side script as Drew mentioned:
Page.RegisterStartupScript() and Page.RegisterClientScriptBlock()

You might find the following article helpful:

Working with Client-Side Script
http://tinyurl.com/3w474

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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
474,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top