<asp:HiddenField ID="hdnIsNew" runat="server" Value="N" />In my button code I am setting it to "Y" as below.
protected void btnAddTruck_Click(object sender, EventArgs e) { // Retrieve the previous Trucks DataSet this.LoadUpdateableTrucksDataSet(); // Add a new Row to the DataSet this.oTruck.NewRow(this.dsTrucks); // Set the hidden field on the Client Side hdnIsNew.Value = "Y"; // Store the DataSet back into the Session this.SaveUpdateableTrucksDataSet(); // Set the row for Editing - Apparently we can't do this here, // we need to do this on client side after it returns. //this.grdTrucks.EditIndex = dsTrucks.Tables[this.oTruck.TableName].Rows.Count - 1; // Rebind the Grid this.BindControl(this.grdTrucks); }In my script file I have these functions that I thought would run.
function grdTrucks_InitializeGrid(gridId) { var oGrid = igtbl_getGridById(gridId); // Does this run after a postback also // Can i check here for the hidden field and // call EditAfterNew() if "N"? var hidden = document.getElementById("hdnIsNew"); if (hidden.value == "Y") { EditAfterNew(gridId); // Set the hidden value back hidden.value = "N"; } } // This is to place the newly added row in edit mode function EditAfterNew(grdId) { // Cause the new row to be placed in Edit mode with Template var oGrid = igtbl_getGridById(gridId); var lastRow = oGrid.rows.getRow(oGrid.Rows.length - 1); lastRow.Activate(); // Place the row into template edit oGrid.BeginEditTemplate(); }This doesn't work and I am a bit confused about the code you posted that would cause a script to run after the browser is loaded. Where do I put code to inject script inito the page?
><script language="javascript" type="text/javascript" > function SetValue() > { > var myControl = document.getElementById('txtHidden'); > if (myControl) > document.forms[0].submit(); > // Instead of this you can use ASP.NET's __doPostback code to fire the postback. If you use it, it's then possible to intercept this info in the page > // __doPostBack('ControlOrEventCausingPostback', 'AnyParameters'); > // In that case, you don't need the hidden input - pass the parameter as the second parameter of __doPostBack > } ></script ><input type="hidden" name="txtHidden" / > >// In your ASP.NET code-behind: >if (Page.IsPostBack) >{ > string hiddenValue = Request.Form["txtHidden"]; > // Do something > // Or if you are using ASP.NET's __doPostBack you can do this in Page_Load: > // string eventName = Request.Form["__EVENTTARGET"]; > // string arg = Request.Form["__EVENTARGUMENT"]; > // if (eventName == "ControlOrEventCausingPostback") > // this.DoSomething(arg); >} > >>
>string script = "<script type=\"text/javascript\">JSFunctionToRun();</script>"; >Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "JustNameOfScript", script); >// You can actually call RegisterClientScriptBlock with a 4th parameter of true - that will add the <script tag stuff for you. >>