Results 1 to 2 of 2

Thread: Javascript in Filename.aspx.cs

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    Javascript in Filename.aspx.cs

    Hi Guys,

    Anyone here knows how to use Javascript in .aspx.cs.


    I have here the code for my Button controls.

    Code:
        protected void Button1_Click(object sender, EventArgs e)
        {
            lblMessage.Text = "";
            Button1.Attributes.Add("OnClick", "javascript:history.back()");
        }
    It can't go back to my previous page.

    Thanks in advance.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript in Filename.aspx.cs

    When you click button1, the page posts back. It then adds the onclick attribute to the button. When you then click on the button again, it'll go back one page, but that'll be the page that had the button without the javascript on it.

    You should be doing this in the Page Load event and use a button that does not have a postback associated with it.

    <input type="button" onclick="javascript:history.back();" value="Back"/>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width