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.
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?
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?
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?
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.
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.
Hello.
First time I have such id - UltraWebGrid1$ctl00$Control1, but when I click OK in temlate it is the update panel post back. And after it I have such id - UltraWebGrid1$ctl04$Control1(Another id!). So I can not use hard coded ids. That's why I need to write beforeRowTemplateOpen() in the event handler - I need to put correct Ids in it. Could you please make an example for my problem - and you will see what I'm talking about.
I've tried this and I get the same Id everytime the grid posts back inside the WARP.
What version of NetAdvantage including the build number are you using? What version CLR?
And what exactly is the control you have inside the template? Make sure nothing is changing when you implement your code.
Dear Duc, I have fixed my problem with another way. Thanks for your answers. Good bye.
Ok, there seems to be some issues with the 8.2 release build. I cannot get a clientside event to trigger while the grid is inside the WARP. I don't know if you experienced this issue. However, I'ved tried this with an 8.3 release build and my events trigger correctly. I was able to get reference to the controls inside your user control everytime, using a hardcoded id, even after the grid updates:
I am not sure if your issue is caused by the 8.2 build but I cannot test it because of the issue I mentioned, which is most likely a bug. You should test this in the latest hotfix of 8.2 or upgrade to the 8.3 version. Further, you can contact developer support to verify that your issue is caused by a bug. I have searched the current known issues and did not find anything on this.
I use NetAdvantage for .NET 2008 vol. 2 CLR 3.5
Version: 8.2.20082.1000
My template control has such structure:
<asp:Panel > <table> <tr> <td> <Controls:TextBox ID="tbShiftTypeName" runat="server" columnKey="Name" Width="100%" /> </td> </tr> <tr> <td> <Controls:DropDownList ID="ddlColor" runat="server" columnKey="ColorName" /> </td> </tr> <tr> <td> <div id="divColor" style="width: 100%; height: 3px; padding: 0px;" runat="server" columnKey="Color"/> </td> </tr> </table> <div > <input id="OkBtn" /> <input id="CancelBtn"/> </div></asp:Panel> And I need ddlColor and divColor to be fill with some default values.
But problem is : they have another Ids after WARP postback.