Use the RegisterClientS criptBock method. Example:
--codebehind for somepage.cs, which uses a masterpage (although this doesn't
matter)
Page.aspx:
<input type="button" onclick="someth ing();" value="click me" />
Page.aspx.cs:
protected void Page_Load(objec t sender, EventArgs e)
{
Page.RegisterCl ientScriptBlock ("uniqueString" , "<script
type=\"text/javascript\">fu nction something(){
alert('somethin g'); }</script>");
}
Doing the Javascript construction in the .cs file can get annoying and
messy, so I will often put the javascript in the aspx (or ascx) file in a
literal control that I never display, but read the contents of, like so:
Page2.aspx:
<input type="button" onclick="somefu nction();" value="clickme" />
<asp:Literal ID="litClientSc ript" runat="server" Visible="false" >
<script type="text/javascript">
function somefunction() {
var x = 3;
var y = 9;
alert(x*y);
}
</script>
</asp:Literal>
Page2.aspx.cs:
protected void Page_Load(objec t sender, EventArgs e)
{
Page.RegisterCl ientScriptBlock ("clientScript" , litClientScript .Text);
}
Ray at work
<bb****@yahoo.c omwrote in message
news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
Hi,
I have a master page and content page. In content page I have to
validate the text boxes for
name,address, phone number and email address etc. But as content pages
doersn't have html section not head or body section so, where I use
this java script in content page to validate the form.
Thanks