ASP.NET - How do i check that which view is active

Asked By Hozefa Unwala on 14-Oct-11 12:07 PM
How can i check in javascript that which view is active right now inside mutliview.

I have one multiview and 3 views inside of it.
If i will change one view to another view then how can i check wih javascript that which view is currently active?
Thanks.
Kirtan Patel replied to Hozefa Unwala on 14-Oct-11 12:19 PM
here is code to get that Which View Is Active Currently using JavaScript 

<asp:MultiView ID="MultiView1" runat="server">
  <asp:View ID="View1" runat="server">
    View1
  </asp:View>
  <asp:View ID="View2" runat="server">
    View2
  </asp:View>
  <asp:View ID="View3" runat="server">
    View3
  </asp:View>
</asp:MultiView>
<script type="text/javascript">
    var CurrentView = <%= MultiView1.ActiveViewIndex %>
     alert("Current Active View Index Is :"+CurrentView);
</script>
Hozefa Unwala replied to Kirtan Patel on 14-Oct-11 12:35 PM
This is working but my multiview control is inside the update panel

Asked By Hozefa Unwala on 14-Oct-11 12:46 PM
I already used this things but If I am using update panel and If I am writing javascript code inside content template then Index is always getting 0 not 1
Kirtan Patel replied to Hozefa Unwala on 14-Oct-11 01:41 PM
if your MultiView is Inside the Update Panel then Code like below

<script type="text/javascript">
var CurrentView = <%=(UpdatePanel1.FindControl("MultiView1") as MultiView).ActiveViewIndex %>
alert("Current Active View Index Is :"+CurrentView);
</script>
  
Thanks
Hozefa Unwala replied to Kirtan Patel on 14-Oct-11 02:01 PM
Can you please try on your system first and then upload the whole code
Thanks.
Kirtan Patel replied to Hozefa Unwala on 14-Oct-11 02:06 PM
UI



Code Behind
  protected void Page_Load(object sender, EventArgs e)
  {
    (UpdatePanel1.FindControl("MultiView1"as MultiView).ActiveViewIndex = 1;
  }
ASPX Code
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<script type="text/javascript"> var CurrentView = <%=  (UpdatePanel1.FindControl("MultiView1") as MultiView).ActiveViewIndex %> alert("Current Active View Index Is :"+CurrentView); </script> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server">   <ContentTemplate>     <asp:MultiView ID="MultiView1" runat="server">       <asp:View ID="View1" runat="server">         View1       </asp:View>       <asp:View ID="View2" runat="server">         View2       </asp:View>       <asp:View ID="View3" runat="server">         View3       </asp:View>     </asp:MultiView>   </ContentTemplate> </asp:UpdatePanel> </form>

Result :




Hozefa Unwala replied to Kirtan Patel on 14-Oct-11 03:05 PM
If you put one button inside view2
and write a code in button click event that
MultiView1.SetActiveView(View1);

It will fire the event and set view1 but it will not come with alert