Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Newbie - Passing Variables from a code behind page to a .js and back again

    ok, Im trying to learn javascript by replacing some of my old code with javascript equivalents, or new ways of doing things. However Ive kinda become stuck and need a little help.

    I'll try to add as much detail as I can. my issue:

    In my webpage code behind page Im filling a stringbuilder with html code to be shown at a certain point in my web page.

    This is what I have so far to show a button that needs to, when clicked go to a .js file called 'main.js' (ive already included it) to a function called 'AddExistingEmployees'

    stringbuilder.Append("<input type=""button"" id=""" & incAddButton & """ onClick=""AddExistingEmployee(" & count & ", " & varBranch & ", """ & varDepartment & """, """ & varSicknessReason & """, """ & varCode & """, " & varHours & ", " & varEndDate & ", " & varStartDate & ", " & varpayroll & ", """ & varUserName & """)"" NAME=""add" & count & """ VALUE=""add""></td>

    (The output html on the aspx page becomes: )

    input type="button" id="btnAdd1" onClick="AddExistingEmployee(1, 0, "NULL", "NULL", "NULL", -2147483648, 00:00:00, 00:00:00, 0000033, "Mr. X")" NAME="add1" VALUE="add"></td>

    My issue is, i need to pass the variables given in the brackets to the js:

    I've started it off:

    function AddExistingEmployee(Count, Branch, Department, SicknessReason, Code, Hours, EndDate, StartDate, Payroll, UserName)
    {
    __doPostBack('AddExistingEmployee')
    }


    So my question is how do I get the contents of those Variables back to the code behind page. I figured a dopostback would work but what next?

    This is my sub on the code behind (vb.net)

    Private Sub AddExistingEmployee(ByVal Count As Integer, ByVal branch As Integer, ByVal department As String, ByVal SicknessReason As String, ByVal Code As String, ByVal Hours As Date, ByVal EndDate As Date, ByVal StartDate As Date, ByVal Payroll As String, ByVal UserName As String)

    'stuff here


    End sub

    I'm sorry if this is really noddy stuff but Im new to javascript and I don't know what the above is called to be able to search for help on it. (I dont know what Im searching for)

    If anyone can help finishing off this function Id really appreciate it. (And explain why/how you've done it)

    Thanks guys


  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I can't really help here, but I'm curious why you're doing this.
    It seems a bit, well, unusual.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jan 2007
    Location
    California, United States
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am kinda confused, but:
    input type="button" id="btnAdd1" onClick="AddExistingEmployee(1, 0, "NULL", "NULL", "NULL", -2147483648, 00:00:00, 00:00:00, 0000033, "Mr. X")" NAME="add1" VALUE="add"></td>

    Should be:
    input type="button" id="btnAdd1" onClick="AddExistingEmployee(1, 0, 'NULL', 'NULL', 'NULL', -2147483648, 00:00:00, 00:00:00, 0000033, 'Mr. X')" NAME="add1" VALUE="add"></td>

    (Single quotes)

    ???

    Also, are you getting some error?


  •  

    Posting Permissions

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