I'm fairly new to the marriage of C# and javascript in the same application. I think I must be missing some important piece of making them work together. Calling my javascript function from my codebehind doesn't result in the outcome I expect, but doesn't result in an error either. Simply nothing happens. I am developing with Visual Studio 2010, and if there as a debugger for JS built in, I don't know where to find it - not being able to step through is making this much more aggravating.
In my .aspx (both "FieldName" values come from another part of the code):
<script language ="javascript">
var idSelection;
var nameSelection;
function selectRow(idItem, nameItem) {
idSelection = idItem;
nameSelection = nameItem;
alert(idSelection + " " + nameSelection);
var targetIdValue;
var targetForm = window.opener.document.forms(0);
eval("targetForm." + targetIdFieldName + ".value = '" + idSelection + "';");
eval("targetForm." + targetNameFieldName + ".value = '" + nameSelection + "';");
window.close();
}
</script>
And my call:
protected void AppGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
txthidAppId = (HtmlInputHidden)Session["hidAppId_rvte"];
txtAppName = (TextBox)Session["txtAppName_rvte"];
txthidAppId.Value = selectedApp.Id;
txtAppName.Text = selectedApp.Name;
Page.ClientScript.RegisterStartupScript(GetType(), "SelectApp", "selectRow(" + txthidAppId.Value + ", " + txtAppName.Text + ")", true);
}