I have a Project Server 2013 deployment on top of SharePoint2013 environment, and I deployed a webpart that registers a JavaScript on the page, during Page_Load. In this JavaScript I change the value of one input box of a Project Details Page. However, after the page is completely rendered, the new value doesn't appear on the input box, and the input box is still enabled. Strange thing is that I have added a JavaScript alert to the point in which the value is changed, and I can see the alert window, so the script runs. And another strange thing is that if I use IE Developer Tools to debug this and I set a breakpoint in the script, and follow it line by line, then when the page is rendered the value is changed and the box is disabled. How can I change the value of the input box? And why does it work if I debug on Developer Tools, but doesn't work if I just let the script run normally? This is my C# code:
public partial class SpecialIDUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
String fieldGUID = "THIS_A_FIELD_GUID"
String specialId = "bla bla bla"
String javaScript = @"SetSpecialID('" + fieldGUID + "','" + specialId + "');";
ScriptManager.RegisterStartupScript(this, GetType(), "initializeVar", javaScript, true);
}
catch (Exception ex)
{
// stuff
}
}
}
And this is my JavaScript
function SetSpecialID(fieldId, specialId) {
var $puidElement = $("[GUID='" + fieldId + "']");
$puidElement.val(specialId);
WPDPParts[0].IsDirty = true; //makes the page dirty, so the user gets a notification for saving
}
$puidElement.attr('disabled', 'disabled'); //disables input box, since this field should not be manually changed
}
Try this:
id_field = "field_name";
$('input[title="'+id_field '"]').attr("value",specialId);
$('input[title="'+id_field +'"]').attr("LTValue",fieldGUID);