Results 1 to 9 of 9

Thread: [RESOLVED] HOW to write Javascript in VB.NET?

  1. #1

    Thread Starter
    Addicted Member NinaWilliam's Avatar
    Join Date
    May 2005
    Location
    @Home
    Posts
    133

    [RESOLVED] HOW to write Javascript in VB.NET?

    how can i write if statment in javascript that returns true or false values to vb.net

    i mean.. how can i do it to look like the following

    javascript code:if (confirm('Are you sure you want to book an appiontment??'))
    {return true;

    do some VB.NET Code

    } else {

    return false;

    Do some other VB.NET Code

    };

    Please help...
    Last edited by NinaWilliam; Mar 8th, 2006 at 02:04 AM.

  2. #2

    Thread Starter
    Addicted Member NinaWilliam's Avatar
    Join Date
    May 2005
    Location
    @Home
    Posts
    133

    Re: HOW to write Javascript in VB.NET?

    come on guys... help me

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

    Re: HOW to write Javascript in VB.NET?

    You cannot. Instead, you'll have to submit the page with a hidden value set somewhere, so that vb.net can look at it and perform appropriate actions.

  4. #4
    Lively Member
    Join Date
    Nov 2003
    Location
    Amsterdam
    Posts
    74

    Re: HOW to write Javascript in VB.NET?

    Quote Originally Posted by NinaWilliam
    how can i write if statment in javascript that returns true or false values to vb.net

    i mean.. how can i do it to look like the following

    javascript code:if (confirm('Are you sure you want to book an appiontment??'))
    {return true;

    do some VB.NET Code

    } else {

    return false;

    Do some other VB.NET Code

    };

    Please help...
    This is not possible, as far as my knowledge goes. You have to separate the Javascript function in the aspx page and store the return value in some hidden field. Call the javascript method in the button click using attributes.add and check for the return value in the hidden field in the event handler for the button.
    Hope this helps.
    Everything I code, is a piece for Museum.

  5. #5

    Thread Starter
    Addicted Member NinaWilliam's Avatar
    Join Date
    May 2005
    Location
    @Home
    Posts
    133

    Re: HOW to write Javascript in VB.NET?

    thanks..but can you show me the code please?? i really need your help guys

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

    Re: HOW to write Javascript in VB.NET?

    VB Code:
    1. If blnSomeCondition Then
    2. Page.RegisterStartupScript(.....)
    3. Else
    4. Page.RegisterStartupScript(........)
    5. End If

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: HOW to write Javascript in VB.NET?

    Code:
    <head>
    <meta...
    ...
    ...
    <script language="javascript" type="text/javascript">
    function DoSomething()
    {
    if (confirm("Do you wish to continue?"))
    {
     document.getElementById('hiddenChoice').value = 1;
     document.forms[0].submit;
    }
    else
    {
     document.getElementById('hiddenChoice').value = 0;
     document.forms[0].submit;
    }
    }
    </script>
    </head>
    <body>
    <form id="Form1" runat="server">
    <input type="hidden" runat="server" id="hiddenChoice" />
    <input type="button" id="launch" onclick="DoSomething()" />
    ....
    In your code-behind:
    VB Code:
    1. 'declerations section
    2. Protected hiddenChoice As System.Web.UI.HtmlControls.HtmlInputHidden
    3.  
    4.  
    5. Private Sub hiddenChoice_ServerChange (Sender As System.Object, e As System.EventArgs)
    6. If hiddenChoice.Value = 1
    7.  'do some code
    8. Else
    9.  'do some other code
    10. End If
    11. End Sub
    Last edited by nemaroller; May 24th, 2005 at 06:48 AM.

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: HOW to write Javascript in VB.NET?

    You could also use an XMLHTTP request, but that is probably more involved than using a hidden input field.

  9. #9

    Thread Starter
    Addicted Member NinaWilliam's Avatar
    Join Date
    May 2005
    Location
    @Home
    Posts
    133

    Re: HOW to write Javascript in VB.NET?

    hmmmmmmm... thats good.. very good code.

    thanks and happy programming

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