Undefined

talk talk about Umbraco, .NET

Updating xslt macro content on postback .net usercontrol

, , , ,

Situation:
- i have a .net usercontrol with updatepanel (login control, so i login, and the control says 'Welcome Gerty')
- i have an xslt macro in umbraco, which lists the navigation

Problem:
when i login i want the profile page to appear in the navigation.

Options:
- (cfr Neehouse) put navigation on an alttemplate and (re)load content in a div with jquery (this was not an option for us since we already use alttemplates and thus in certain places should be having alttemplates on alttemplates which would give problems)
- make the macro refresh........yes

How:
Well, i'll start by saying i think it's a crap way of doing it. But i currently have no idea on how to 'solve' it in a decent way. Suggestions are very welcome! And i don't know if it'll work on slow internet connections...still to test...

<script runat="server" type="text/C#">
      
    protected void Page_Load(object sender, EventArgs e)
    {
        string javascriptCode = @"function test(){var hiddenFieldID = '" + HiddenField2.ClientID + "';var hiddenField = $get(hiddenFieldID);if (hiddenField) { if( hiddenField.value != new Date().getSeconds()){ hiddenField.value = (new Date()).getSeconds(); __doPostBack(hiddenFieldID,'');}}}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SomeKey", javascriptCode, true);
        ScriptManager sm = ScriptManager.GetCurrent(Page);
        if (sm.IsInAsyncPostBack)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(),"anotherKey","test();",true);            
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "anotherKey", "Sys.Application.add_load(test);", true);            
        }
    }
</script>
	------
<asp:UpdatePanel ID="pnlMainNav" runat="server"  UpdateMode="Conditional" ChildrenAsTriggers="False">
	<ContentTemplate>
		<umbraco:Macro Alias="ListMainNavigation" runat="server"></umbraco:Macro>
		<asp:HiddenField ID="HiddenField2" runat="server" /> 
	</ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="HiddenField2" EventName="ValueChanged" />
            </Triggers>
</asp:UpdatePanel>
	------


So what this will do is when i do something in my .net usercontrol it'll call the javascript function 'test' which will then update the contents of the hiddenfield in the updatepanel where my xslt macro stands and do a postback which will trigger the updatepanel of my xslt macro to refresh.

The crappy part of this whole chabbang is that when i don't add a check in it they will constantly refresh each other... resulting thus in an endless loop... therefor i added a check in the javascript and if the value (seconds of time) in the hiddenfield is the same as it is now it'll end....

So conclusion it is dirty but it works ( ! not tested on slow speed connections)
And if anyone has a better solution or improvement suggestions, please let me know smile




Reading an Excel file on a 64 bit server!My way of building Umbraco sites in different languages

Write a comment

New comments have been disabled for this post.