I’ve recently ran into a strange problem in ASP.NET. Being a desktop developer, I like to put interactions in my applications. What I wanted to do was very simple: After a grid postback (grid operation like update or create/delete), I wanted to show a status message to the user. This can be done easily with a button click event but since I was using DevExpress ASPxGridView, I couldn’t bind the UpdatePanel events to it’s postback event (I did but it didn’t work). I tried ways to force partial render but none gave the result I wanted. Here, I’m giving the solution I came up with:
It uses an UpdatePanel and Javascript.
The Javascript part:
<script type="text/javascript">
function updateStatusText() {
__doPostBack("< %= UpdatePanel.ClientID%>", '');
}
</script>
What we do here is simple, we add a Javascript function which forces a postback of the desired control (UpdatePanel in our case)
Here’s the UpdatePanel control:
<asp :ScriptManager ID="ScriptManager" runat="server"></asp> <asp :UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional"> <contenttemplate> < %=StatusMessage%> </contenttemplate> </asp>
It uses a variable as content template.
The variable:
public string StatusMessage
{
get
{
return (Session["statusMessage"] == null) ? string.Empty : Session["statusMessage"].ToString();
}
set
{
Session["statusMessage"] = value;
}
}
Finally, add this to your ASPxGridView properties:
<clientsideevents EndCallback="function(s, e) { updateStatusText(); }" />
What we did: We told ASPxGridView to call updateStatusText() Javascript method after it’s callback is finished. And we forced a postback targeting the desired control (UpdatePanel) to update it’s properties. Since we use an UpdatePanel, you will see a partial page render (not whole page reloading) which is bound to our Session variable, set to show the status text available. I played with extra control postbacks but UpdatePanel is the best choice if you want to see AJAX in action.
Enjoy,
Bora Bilgin

One Response
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Continuing the Discussion