Hello!
I have a big problem with a very simple thing.
I have WebAsyncRefreshPanel, UltraWebGrid and EditRowTemplate. I need to set controls in template to some default values before open template window. (Now if user changes values in template and click Cancel this values will be there when user opens temlate again).
I will not describe all the way how I tried to do this. My solutions were comlicated and not perfect. May be you can offer simple way for this simple problem.
Thanks in advance.
Svetlana.
When you have a control within a template, it will have additional strings attached to its clientside id, depending on what it is nested within. So if you have a TextBox with id TextBox1 nested within a template, your clientside id may look like this: UltraWebGrid1$ctl00$TextBox1. This is just an example and your id may not look anything like that; However, you can get the client-side id of your control by looking at the rendered HTML of the page. Do a search for the id of the controls within the template and you will find the "hardcoded" id to use. Once you have that, your function need nothing more than be:
function beforeRowEditTemplateOpenHandler() {
setDefaultColor(UltraWebGrid1$ctl00$Control1, UltraWebGrid1$ctl00$Control2);
}
You would only need to set the string name of the function as the event handler for the clientside event of WebGrid.
My question was about you calling beforeRowTemplateOpen() within the event handler. Why are you doing that and what is "beforeRowTemplateOpen."
Tell me if this works for you.
1) What do you mean "hard-coded id"? My controls in template have Ids, but if I use <%=Control.ClientID%> this will not be updated after update panel postback. So I send IDs as parameters - in this case they are updated. May be there is another way to get correct IDs?
2) I can't register script in Page_Load because I "do not have " template there (template = (ShiftTypeTemplate)m_grid.Bands[0].RowEditItem.FindControl("tplEditShiftType"); --- this returns null)
Script registers in my example but only once. Is there any mechanism to register it again and again?
And sorry, but I don't comletely undersand the last question.
A couple of things I see with your approaches. In the first approach, if you want the correct id of the control, you need to either use the hard-coded id which you can get from the source of the page, or use <%=Control.ClientID%> to pass in the id for your control.
In the second approach, you should register the clientside method in PageLoad as before. I also notice you called beforeRowTemplateOpen() in the handler for the event. What is the reason for this?
Hi! Thanks for your answer.
Yes I have such construction:
<webasyncrefreshpanel id="warpShiftTypes"> <ultrawebgrid id="m_grid"> <Bands> <Band> <RowEditTemplate> <My Control id="tplEditShiftType"> </RowEditTemplate> ..........
I have tried BeforeRowTemplateOpen event.
*Script function setDefaultColor is on template's .aspx page.
1 way:
*Here script function beforeShiftTypeTemplateOpen is registered from page's .aspx.cs file
****page.aspx.cs ****
protected void Page_Load( object sender, EventArgs e ) { m_grid.InitializeLayout += new InitializeLayoutEventHandler(InitializeLayout); m_grid.ClientEvents.BeforeRowTemplateOpenHandler = "beforeShiftTypeTemplateOpen";
protected void InitializeLayout(object sender, EventArgs e) { ShiftTypeTemplate template = new ShiftTypeTemplate(); template = (ShiftTypeTemplate)m_grid.Bands[0].RowEditItem.FindControl("tplEditShiftType"); string ddlColorID = template.DdlColorClientID; string divColorID = template.DivColorClientID; string script = "function beforeShiftTypeTemplateOpen() { "
+ String.Format("setDefaultColor('{0}', '{1}');", ddlColorID, divColorID) }";
warpShiftTypes.RegisterScript(script); //register script in UpdatePanel (simply writes script in HTML) }
Problem: I get error message because my controls in template have another IDs after async postback. But script already registered. Can you tell me how to register script in update panel properly (I want it to update after postback)
2 way:
*Here script function function beforeShiftTypeTemplateOpen is located on page's .aspx file
***page.aspx ***
function beforeShiftTypeTemplateOpen (ddlColorID, divColorID) { setDefaultColor(ddlColorID, divColorID); beforeRowTemplateOpen();}
protected void Page_Load( object sender, EventArgs e ) { m_grid.InitializeLayout += new InitializeLayoutEventHandler(InitializeLayout);
protected void InitializeLayout(object sender, EventArgs e) { ShiftTypeTemplate template = new ShiftTypeTemplate(); template = (ShiftTypeTemplate)m_grid.Bands[0].RowEditItem.FindControl("tplEditShiftType"); string ddlColorID = template.DdlColorClientID; string divColorID = template.DivColorClientID;
m_grid.ClientEvents.BeforeRowTemplateOpenHandler = String.Format("beforeShiftTypeTemplateOpen(\'{0}\', \'{1}\');", ddlColorID, divColorID);
Problem: It works but I get error message (because of inline javascript in BeforeRowTemplateOpenHandler):There is a problem with the event handler method: 'beforeShiftTypeTemplateOpen('ctl00_Content_dialog_gbTabs_tabs__ctl2_ctrlShiftTypes_m_grid_m_grid_ctl00_tplEditShiftType_ddlColor', 'ctl00_Content_dialog_gbTabs_tabs__ctl2_ctrlShiftTypes_m_grid_m_grid_ctl00_tplEditShiftType_divColor');'. Please check the method name's spelling.How can I overcome this?
Hello,
The EditRowTemplate is designed to be able to automatically retrieve values from the row being edited and display the values in the editors of the template. If you want to calculate the values on your own, you need to handle the BeforeRowTemplateOpen clientside event of the grid. Have you tried this approach? Further, is the grid embedded in the WebAsyncRefereshPanel or do you have that placed in your template?