VBAHole22 Posted January 31, 2006 Posted January 31, 2006 I have an editable data grid. When the user clicks the edit button I change a textbox to a dropdown so they can select a new value. I also add a js attribute to the save button so they get prompted for confirmation before commiting the save. This works well for me as I can inform the user of the state they are changing the value FROM before they commit. What I can't figure out is how I can get a handle on what they are changing the value TO before they commit. This is because my js gets bound with the grid, before the user chooses. I could put an auto post back on the ddl but that would be a little cumbersome I think for the user. If I could just get a handle on the ddl in js I could get the selected value. Trouble is the ddl doesn't maintain the id I give it in html. It gets appended with the .NET ctl_ syntax so I can't use js document.getElementById("ddl"); Is there another way to do this? Quote Wanna-Be C# Superstar
bri189a Posted February 1, 2006 Posted February 1, 2006 how about you have your javascript function called with the 'this' as an arugument: 'In ItemDataBound If e.Item.ItemType = ListItemType.EditItem Then Dim dgi as DataGridItem = DirectCast(e.Item, DataGridItem) Dim cntl as Control = e.Item.Cells(0).FindControl("DropDownList1") If Not cntl Is Nothing Then DirectCast(cntl, DropDownList).Attributes.Add("onmousedown", "MyJavaScriptSetCurrentValue(this)") DirectCast(cntl, DropDownList).Attributes.Add("onchange", "MyJavaScriptConfirmFunction(this)") End If End If Now you javascript would be something like: var curValue; function MyJavaScriptSetCurrentValue(cntl) { curValue = cntl.value; } function MyJavaScriptConfirmFunction(cntl, currentValue) { if(confirm('Are you sure?')) return; else cntl.value = curValue; } ***Note this may not be the best method but it will get the job done...you might want to take the time to do something a little more robust like setting a hidden input tag to the current value that has a similiar name, or something like that. Hope this helps. Quote
VBAHole22 Posted February 1, 2006 Author Posted February 1, 2006 Pure genius. Thanks bri. Quote Wanna-Be C# Superstar
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.