Page.ClientScript.RegisterClientScriptBlock renders incorrectly

S

Scott M.

The following code (VS 2008) does cause the script string to render, but it
doesn't render inside of <script> tags, instead the result is rendered just
after the opening <form> tag, but outside of the other <script> tags that
are rendered automatically to handle my validation controls.

protected void Page_Load(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"function vailidateCardType(sender, args){");
sb.Append(@"if(form1.elements['lstCardType'].selectedIndex == 0)");
sb.Append(@"{args.IsValid = false;}");
sb.Append(@"else {args.IsValid = true;}");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"customValidator",
sb.ToString());
}

Any ideas?
 
S

Scott M.

Nevermind, I wasn't entering the 4th optional argument of true to indicate
that I wanted the <script> tags to render.

But, how could this method work without rendering the <script> tags?
 
B

bruce barker

you supply the tags yourself. the only option for people writing in a script
other than javascript.if yo use the script flag, all the registered block go
into one script tag.

-- bruce (sqlwork.com)


Scott M. said:
Nevermind, I wasn't entering the 4th optional argument of true to indicate
that I wanted the <script> tags to render.

But, how could this method work without rendering the <script> tags?

Scott M. said:
The following code (VS 2008) does cause the script string to render, but
it doesn't render inside of <script> tags, instead the result is rendered
just after the opening <form> tag, but outside of the other <script> tags
that are rendered automatically to handle my validation controls.

protected void Page_Load(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"function vailidateCardType(sender, args){");
sb.Append(@"if(form1.elements['lstCardType'].selectedIndex == 0)");
sb.Append(@"{args.IsValid = false;}");
sb.Append(@"else {args.IsValid = true;}");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"customValidator",
sb.ToString());
}

Any ideas?
 

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

Top