...

View Full Version : Newbie - Passing Variables from a code behind page to a .js and back again



kirstyb83
01-10-2007, 01:02 PM
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: :confused:

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

:p

nikkiH
01-10-2007, 03:49 PM
I can't really help here, but I'm curious why you're doing this.
It seems a bit, well, unusual.

frosty1433
01-10-2007, 03:50 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum