Showing posts with label basically. Show all posts
Showing posts with label basically. Show all posts

Monday, March 26, 2012

MultiView inside UpdatePanel - Validators not working

Hi All,

I have a problem with a page I'm building at the moment. Basically it includes a multiview with a number of views, in which where there is a usercontrol that contains a number of text fields with custom validators.

Without an updatepanel around the multiview, all works fine. However, when I put an updatepanel around the multiview to prevent full page rendering on postback, the valdidators fail. I have included a very simplified example below to explain my point.

My ASPX Page:

1<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>23<%@dotnet.itags.org. Register src="http://pics.10026.com/?src=WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">5<html xmlns="http://www.w3.org/1999/xhtml">6<head runat="server">7 <title>Untitled Page</title>8</head>9<body>10 <form id="form1" runat="server">11 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />12 <br />13 <asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline" UpdateMode="Always">14 <ContentTemplate>15 <asp:Button ID="Button1" runat="server" Text="View 1" OnClick="Button1_Click" CausesValidation="false" />16 <asp:Button ID="Button2" runat="server" Text="View 2" OnClick="Button2_Click" CausesValidation="false" />17 <asp:Button ID="Button3" runat="server" Text="View 3" OnClick="Button3_Click" CausesValidation="false" />18 <br />19 <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">20 <asp:View ID="View1" runat="server">21 <asp:Label ID="Label1" runat="server" Text="View 1"></asp:Label>22 <uc1:WebUserControl ID="WebUserControl1" runat="server" />23 </asp:View>24 <asp:View ID="View2" runat="server">25 <asp:Label ID="Label2" runat="server" Text="View 2"></asp:Label>26 <uc1:WebUserControl ID="WebUserControl2" runat="server" />27 </asp:View>28 <asp:View ID="View3" runat="server">29 <asp:Label ID="Label3" runat="server" Text="View 3"></asp:Label>30 <uc1:WebUserControl ID="WebUserControl3" runat="server" />31 </asp:View>32 </asp:MultiView>33 </ContentTemplate>34 </asp:UpdatePanel>35 </form>36</body>37</html>38
Code Behind:
1public partialclass _Default : System.Web.UI.Page {2protected void Page_Load(object sender, EventArgs e) {3 }4protected void Button1_Click(object sender, EventArgs e) {5this.MultiView1.ActiveViewIndex = 0;6 }7protected void Button2_Click(object sender, EventArgs e) {8this.MultiView1.ActiveViewIndex = 1;9 }10protected void Button3_Click(object sender, EventArgs e) {11this.MultiView1.ActiveViewIndex = 2;12 }13}
 The User Control:
 
1<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"2 Inherits="WebUserControl" %>34<script type="text/javascript">5 function v(sender, args) {6 var v1 = $get("<%=TextBox1.ClientID%>");7 alert(v1);8 }9</script>1011<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>12<asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="true" />13<asp:CustomValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"14 Font-Bold="True" Font-Size="X-Large" Text="*" ClientValidationFunction="v" ValidateEmptyText="true" />15

Create the project and add the user control and the default.aspx page. Run it. Try the validator in the View1 (selected by default), it works fine, alerting an [object] to denote the field was found ok.

Switch to another view and all you get alerted is [null] showing the control was not found.

Can anyone get this code to work with the updatepanel?

Andy.

Hi;

Hi;

I had this problem with Ajax Asp.NET Beta 2;
So.. this is a bug, and it was fixed on Features November CTP

http://go.microsoft.com/fwlink/?LinkID=77294

You need download, install and configure the the web.config;
Join it;

[]'s

I was sure I was using the Nov issue. I will check...

Andy.

Saturday, March 24, 2012

Navigation using Master pages and Update panel without refresh

Hi

I have a master page in which there are hyperlinks to go to different pages. Its a header basically. I got the relevant content pages for the hyperlinks.

But when I click the master page links, a postback occurs and the whole page is refreshed and directed to the new page.

I need a way by which when I click the hyperlinks in master page the content pages change without any refreshing. I heard about the Iframe implementaion in update panel is it a feasible way to do this or multiview might solve my problem ?

Having a master page sort of defeats the purpose of keeping the same page and dynamically updating portions on postback. The master page is meant to be a supplement for the page the user is viewing. This means the master page is never browsed directly, it only contains master code for each of the pages that are browsed to directly.

Also, hyperlink controls should not perform postbacks -- they are simply meant for navigation. Therefore, anytime a user clicks a hyperlink, the user will be taken to the new page, causing flicker. I suggest using a link button instead. These perform postbacks and can capture events much better than a hyperlink.

In order to do what you're trying to do, consider not using a master page. Instead, use a single page that makes use of either an iframe or a multiview enclosed in an updatepanel. Example is below:

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="theForm"runat="server">
<divid="wrapper">
<asp:ScriptManagerID="scriptManager"runat="server"></asp:ScriptManager>
<divid="header">
<asp:LinkButtonID="lnkClickMe"runat="server"OnClick="lnkClickMe_Click">Click Me!</asp:LinkButton>
</div>
<asp:UpdatePanelID="pnlDynamicContent"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<asp:MultiViewID="mvDynamicContent"runat="server"ActiveViewIndex="0">
<asp:ViewID="viewBeforeClick"runat="server">
This is before the link above is clicked
</asp:View>
<asp:ViewID="viewAfterClick"runat="server">
This is after the link above is clicked
</asp:View>
</asp:MultiView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="lnkClickMe"EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

And the code-behind:

PartialClass Test_ForumTest
Inherits System.Web.UI.Page

ProtectedSub lnkClickMe_Click(ByVal senderAsObject,ByVal eAs EventArgs)
mvDynamicContent.ActiveViewIndex = 1
EndSub
EndClass


Convert your hyperlink to linkbuttons then register these buttons as AsyncTrigger in the Update Panel. Convert Your Content Pages to User Control. Load the Proper User Control on Button Click.