How To Call Javascript function in asp.net

Discussion in 'ASP .Net' started by hrishikesh, Jan 15, 2004.

  1. hrishikesh

    hrishikesh Guest

    hi all can you tell me how to call javascript function
    in .aspx page
    i want to call it on onclick of button

    this codebehind code giving me some other problem like
    The viewstate is invalid for this page and might be
    corrupted.
    but it goes to that page

    Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As
    System.EventArgs) Handles Button1.Click
    Dim TestString As String = "<script
    language='javascript'>" & _

    "
    window.document.FrmConsultant.action='SearchResume.aspx';"
    & _

    " window.document.FrmConsultant.method='post';" & _

    " window.document.FrmConsultant.submit()</script> "

    Page.RegisterStartupScript("TestString", TestString)

    End Sub

    hrishi
    hrishikesh, Jan 15, 2004
    #1
    1. Advertising

  2. hrishikesh

    Guest Guest

    Hi,

    use

    strScript = @"<script>


    function MyJavascript()
    {
    do all your javascript manipulation/validations


    return true; // if success
    }


    </script>"


    Button1.Attributes.Add("onclick","return MyJavascript();")
    Page.RegisterClientScriptBlock(strScript);


    -Raja

    >-----Original Message-----
    >hi all can you tell me how to call javascript function
    >in .aspx page
    >i want to call it on onclick of button
    >
    >this codebehind code giving me some other problem like
    >The viewstate is invalid for this page and might be
    >corrupted.
    >but it goes to that page
    >
    >Private Sub Button1_Click(ByVal sender As System.Object,
    >ByVal e As
    >System.EventArgs) Handles Button1.Click
    >Dim TestString As String = "<script
    >language='javascript'>" & _
    >
    >"
    >window.document.FrmConsultant.action='SearchResume.aspx';"


    >& _
    >
    >" window.document.FrmConsultant.method='post';" & _
    >
    >" window.document.FrmConsultant.submit()</script> "
    >
    >Page.RegisterStartupScript("TestString", TestString)
    >
    >End Sub
    >
    >hrishi
    >
    >.
    >
    Guest, Jan 15, 2004
    #2
    1. Advertising

  3. hrishikesh

    navyjax2

    Joined:
    Sep 20, 2008
    Messages:
    11
    See my post at social.msdn.microsoft.com/Forums/en/netfxjscript/thread/3efc7bf9-730f-47d0-bc9c-7a3550cf1282.

    -Tom
    navyjax2, Dec 17, 2009
    #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. grbgooglefan
    Replies:
    2
    Views:
    409
    Pascal Bourguignon
    Jan 30, 2008
  2. grbgooglefan
    Replies:
    4
    Views:
    428
    Kenny McCormack
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    0
    Views:
    382
    grbgooglefan
    Jan 30, 2008
  4. Alok
    Replies:
    3
    Views:
    237
  5. THAKUR PRASHANT SINGH

    Class Function call vs Normal Function call

    THAKUR PRASHANT SINGH, Feb 26, 2010, in forum: Ruby
    Replies:
    7
    Views:
    170
    THAKUR PRASHANT SINGH
    Feb 27, 2010
Loading...

Share This Page