Page.ClientScript.RegisterClientScriptBlock renders incorrectly

Discussion in 'ASP .Net' started by Scott M., Sep 9, 2008.

  1. Scott M.

    Scott M. Guest

    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?
    Scott M., Sep 9, 2008
    #1
    1. Advertising

  2. Scott M.

    Scott M. Guest

    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." <> wrote in message
    news:%...
    > 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?
    >
    Scott M., Sep 9, 2008
    #2
    1. Advertising

  3. Scott M.

    bruce barker Guest

    Re: Page.ClientScript.RegisterClientScriptBlock renders incorrectl

    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." wrote:

    > 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." <> wrote in message
    > news:%...
    > > 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?
    > >

    >
    >
    >
    bruce barker, Sep 9, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWFj?=

    Remove clientscript block from page (ASP.NET 1.1)

    =?Utf-8?B?bWFj?=, Jun 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,890
    Jacob
    Jun 20, 2006
  2. Nathan Sokalski
    Replies:
    4
    Views:
    60,999
    Alessandro Zifiglio
    Jul 3, 2006
  3. Stan SR
    Replies:
    3
    Views:
    709
    Laurent Bugnion, GalaSoft
    Oct 6, 2006
  4. Nathan Sokalski

    ClientScript.RegisterClientScriptBlock in ASP.NET 2.0

    Nathan Sokalski, Jul 3, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    236
    Alessandro Zifiglio
    Jul 3, 2006
  5. Alfred Salton

    Treeview renders incorrectly in IE

    Alfred Salton, Aug 18, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    210
    Ignacio Martinez
    Aug 19, 2003
Loading...

Share This Page