Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reload page after setting session variable?

Status
Not open for further replies.
Jan 26, 2001
550
GB
Hi guys

I have a bi-lingual site utilising a masterpage. On each page I have a usercontrol with a 'change language' button, which when clicked cause a postback, which in turn raises a bubble event to the masterpage.
In the bubbled event handler I set the session language variable to reflect the current view language, and let the page finish loading.

The problem is (due to the load order of the page/masterpage/user controls) that the change in language is only reflected on the sections of the page that load after the bubble event handler is called. Upon the next navigational click, the entire page is converted as the session variable had previously been assigned.

How can I overcome this, i.e. set the session variable before anything in the page loads - or, failing that force a page reload after the variable has been set (not really the way I want to go, but something like the pseudocode below).

Code:
Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal e As EventArgs) As Boolean

        Dim cArgs As System.Web.UI.WebControls.CommandEventArgs = CType(e, System.Web.UI.WebControls.CommandEventArgs)
        If cArgs.CommandName = "switchLanguage" Then
            Session("sLang") = cArgs.CommandArgument
        End If

        Page.Reload ****?

    End Function

Nick (Webmaster)

 
Hi Mark

I considered using response.redirect, but I am reluctant to do so as I really want the current viewstate to be preserved when the user switches language, rather than just reloading the page from scratch - e.g. if they have navigated to a certain list or event in a page and wish to view the details in the alternative language.

Thanks for your help
Nick

Nick (Webmaster)

 
Instead of using Response.Redirect you could try

Code:
ScriptManager.RegisterClientScriptBlock(this, typeof(string), "postBack", Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this)), true);

I know it's a bit long but if you have any update panels or ajax stuff on the page you need to use ScriptManager. Otherwise you can just use

Code:
ClientScript.RegisterClientScriptBlock(typeof(string), "postBack", Page.ClientScript.GetPostBackEventReference(new PostBackOptions(this)));

I hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top