By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,724 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,724 IT Pros & Developers. It's quick & easy.

Lazy Load Tabcontainer tabs and content page javascript not working problem

P: 8
Dear All,

Please help me...

I had read an article to lazy load a tab in a tabcontainer using an update panel on

http://mattberseth.com/blog/2007/07/...nels_with.html

and i am implementing it in my website....

in short...when the active tab changes we call a javascript function which then causes a serverclick on a hidden button in the page using the javascript.. __doPostBack() function and then that function causes the formview to display and databind...i have a website where i have 6 formviews in 6 tabs oof a tabcontainer....but the javascript doesnt work and page loads only...i know this problem is caused when u use a master page and so i tried doing it decleratively also using the ASP ClentScriptManager.RegisterClientScriptBlock at page_prerender and it still doesnt work...

placing the javascript code below the <asp:content> tag also doesnt work...

and when i used this trick without using the master page it works fine ...please help me...

i have made a test page that only has 3 tabs and i want the 2nd tab to load....if this works here then i will incorporate this functionality in my main website

please take a look at my page design

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Copy of Copy of Testing.aspx.vb"
  2.     Inherits="Testing" MasterPageFile="~/MasterPage.master" %>
  3.  
  4. <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
  5.  
  6. <asp:Content ID="Content1" runat="server" ContentPlaceHolderID="middleContent">
  7.  
  8.     <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
  9.     </cc1:ToolkitScriptManager>
  10.     <input id="Button1" runat="server" type="button" value="button" onserverclick="Button1C" />
  11.     <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" OnClientActiveTabChanged="clientActiveTabChanged()">
  12.         <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
  13.         </cc1:TabPanel>
  14.         <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
  15.             <ContentTemplate>
  16.                 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  17.                     <ContentTemplate>
  18.                         &nbsp;
  19.                         <asp:FormView ID="FormView1" runat="server" OnItemUpdating="FormView1_ItemUpdating"
  20.                             Visible="False" DataKeyNames="user_id">
  21.                             <EditItemTemplate>
  22.                                 user_id:
  23.                                 <asp:Label ID="user_idLabel1" runat="server" Text='<%# Eval("user_id") %>'></asp:Label><br />
  24.                                 first_name:
  25.                                 <asp:TextBox ID="first_nameTextBox" runat="server" Text='<%# Bind("first_name") %>'></asp:TextBox><br />
  26.                                 last_name:
  27.                                 <asp:TextBox ID="last_nameTextBox" runat="server" Text='<%# Bind("last_name") %>'></asp:TextBox><br />
  28.                                 gender:
  29.                                 <asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>'></asp:TextBox><br />
  30.                                 date_of_birth:
  31.                                 <br />
  32.                                 <asp:DropDownList ID="dob_day" runat="server">
  33.                                     <asp:ListItem>1</asp:ListItem>
  34.                                     <asp:ListItem>2</asp:ListItem>
  35.                                     <asp:ListItem>3</asp:ListItem>
  36.                                     <asp:ListItem>4</asp:ListItem>
  37.                                     <asp:ListItem>5</asp:ListItem>
  38.                                     <asp:ListItem>6</asp:ListItem>
  39.                                     <asp:ListItem>7</asp:ListItem>
  40.                                     <asp:ListItem>8</asp:ListItem>
  41.                                     <asp:ListItem>9</asp:ListItem>
  42.                                     <asp:ListItem>10</asp:ListItem>
  43.                                     <asp:ListItem>11</asp:ListItem>
  44.                                     <asp:ListItem>12</asp:ListItem>
  45.                                     <asp:ListItem>13</asp:ListItem>
  46.                                     <asp:ListItem>14</asp:ListItem>
  47.                                     <asp:ListItem>15</asp:ListItem>
  48.                                     <asp:ListItem>16</asp:ListItem>
  49.                                     <asp:ListItem>17</asp:ListItem>
  50.                                     <asp:ListItem>18</asp:ListItem>
  51.                                     <asp:ListItem>19</asp:ListItem>
  52.                                     <asp:ListItem>20</asp:ListItem>
  53.                                     <asp:ListItem>21</asp:ListItem>
  54.                                     <asp:ListItem>22</asp:ListItem>
  55.                                     <asp:ListItem>23</asp:ListItem>
  56.                                     <asp:ListItem>24</asp:ListItem>
  57.                                     <asp:ListItem>25</asp:ListItem>
  58.                                     <asp:ListItem>26</asp:ListItem>
  59.                                     <asp:ListItem>27</asp:ListItem>
  60.                                     <asp:ListItem>28</asp:ListItem>
  61.                                     <asp:ListItem>29</asp:ListItem>
  62.                                     <asp:ListItem>30</asp:ListItem>
  63.                                     <asp:ListItem>31</asp:ListItem>
  64.                                 </asp:DropDownList><asp:DropDownList ID="dob_month" runat="server" Width="73px">
  65.                                     <asp:ListItem Value="1">January</asp:ListItem>
  66.                                     <asp:ListItem Value="2">February</asp:ListItem>
  67.                                     <asp:ListItem Value="3">March</asp:ListItem>
  68.                                     <asp:ListItem Value="4">April</asp:ListItem>
  69.                                     <asp:ListItem Value="5">May</asp:ListItem>
  70.                                     <asp:ListItem Value="6">June</asp:ListItem>
  71.                                     <asp:ListItem Value="7">July</asp:ListItem>
  72.                                     <asp:ListItem Value="8">August</asp:ListItem>
  73.                                     <asp:ListItem Value="9">September</asp:ListItem>
  74.                                     <asp:ListItem Value="10">October</asp:ListItem>
  75.                                     <asp:ListItem Value="11">November</asp:ListItem>
  76.                                     <asp:ListItem Value="12">December</asp:ListItem>
  77.                                 </asp:DropDownList><asp:DropDownList ID="dob_year" runat="server">
  78.                                 </asp:DropDownList><br />
  79.                                 birth_place:
  80.                                 <asp:TextBox ID="birth_placeTextBox" runat="server" Text='<%# Bind("birth_place") %>'></asp:TextBox><br />
  81.                                 birth_time:
  82.                                 <asp:TextBox ID="birth_timeTextBox" runat="server" Text='<%# Bind("birth_time") %>'></asp:TextBox><br />
  83.                                 city:
  84.                                 <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>'></asp:TextBox><br />
  85.                                 state:
  86.                                 <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>'></asp:TextBox><br />
  87.                                 zipcode:
  88.                                 <asp:TextBox ID="zipcodeTextBox" runat="server" Text='<%# Bind("zipcode") %>'></asp:TextBox><br />
  89.                                 country:
  90.                                 <asp:TextBox ID="countryTextBox" runat="server" Text='<%# Bind("country") %>'></asp:TextBox><br />
  91.                                 profession:
  92.                                 <asp:TextBox ID="professionTextBox" runat="server" Text='<%# Bind("profession") %>'></asp:TextBox><br />
  93.                                 relation_status:
  94.                                 <asp:TextBox ID="relation_statusTextBox" runat="server" Text='<%# Bind("relation_status") %>'></asp:TextBox><br />
  95.                                 languages:
  96.                                 <asp:TextBox ID="languagesTextBox" runat="server" Text='<%# Bind("languages") %>'></asp:TextBox><br />
  97.                                 belongs_to:
  98.                                 <asp:TextBox ID="belongs_toTextBox" runat="server" Text='<%# Bind("belongs_to") %>'></asp:TextBox><br />
  99.                                 interested_in:
  100.                                 <asp:TextBox ID="interested_inTextBox" runat="server" Text='<%# Bind("interested_in") %>'></asp:TextBox><br />
  101.                                 email_id:
  102.                                 <asp:TextBox ID="email_idTextBox" runat="server" Text='<%# Bind("email_id") %>'></asp:TextBox><br />
  103.                                 <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
  104.                                     Text="Update"></asp:LinkButton>
  105.                                 <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
  106.                                     Text="Cancel"></asp:LinkButton>
  107.                             </EditItemTemplate>
  108.                             <InsertItemTemplate>
  109.                                 user_id:
  110.                                 <asp:TextBox ID="user_idTextBox" runat="server" Text='<%# Bind("user_id") %>'>
  111.                                 </asp:TextBox><br />
  112.                                 first_name:
  113.                                 <asp:TextBox ID="first_nameTextBox" runat="server" Text='<%# Bind("first_name") %>'>
  114.                                 </asp:TextBox><br />
  115.                                 last_name:
  116.                                 <asp:TextBox ID="last_nameTextBox" runat="server" Text='<%# Bind("last_name") %>'>
  117.                                 </asp:TextBox><br />
  118.                                 gender:
  119.                                 <asp:TextBox ID="genderTextBox" runat="server" Text='<%# Bind("gender") %>'>
  120.                                 </asp:TextBox><br />
  121.                                 date_of_birth:
  122.                                 <asp:TextBox ID="date_of_birthTextBox" runat="server" Text='<%# Bind("date_of_birth") %>'>
  123.                                 </asp:TextBox><br />
  124.                                 birth_place:
  125.                                 <asp:TextBox ID="birth_placeTextBox" runat="server" Text='<%# Bind("birth_place") %>'>
  126.                                 </asp:TextBox><br />
  127.                                 birth_time:
  128.                                 <asp:TextBox ID="birth_timeTextBox" runat="server" Text='<%# Bind("birth_time") %>'>
  129.                                 </asp:TextBox><br />
  130.                                 city:
  131.                                 <asp:TextBox ID="cityTextBox" runat="server" Text='<%# Bind("city") %>'>
  132.                                 </asp:TextBox><br />
  133.                                 state:
  134.                                 <asp:TextBox ID="stateTextBox" runat="server" Text='<%# Bind("state") %>'>
  135.                                 </asp:TextBox><br />
  136.                                 zipcode:
  137.                                 <asp:TextBox ID="zipcodeTextBox" runat="server" Text='<%# Bind("zipcode") %>'>
  138.                                 </asp:TextBox><br />
  139.                                 country:
  140.                                 <asp:TextBox ID="countryTextBox" runat="server" Text='<%# Bind("country") %>'>
  141.                                 </asp:TextBox><br />
  142.                                 profession:
  143.                                 <asp:TextBox ID="professionTextBox" runat="server" Text='<%# Bind("profession") %>'>
  144.                                 </asp:TextBox><br />
  145.                                 relation_status:
  146.                                 <asp:TextBox ID="relation_statusTextBox" runat="server" Text='<%# Bind("relation_status") %>'>
  147.                                 </asp:TextBox><br />
  148.                                 languages:
  149.                                 <asp:TextBox ID="languagesTextBox" runat="server" Text='<%# Bind("languages") %>'>
  150.                                 </asp:TextBox><br />
  151.                                 belongs_to:
  152.                                 <asp:TextBox ID="belongs_toTextBox" runat="server" Text='<%# Bind("belongs_to") %>'>
  153.                                 </asp:TextBox><br />
  154.                                 interested_in:
  155.                                 <asp:TextBox ID="interested_inTextBox" runat="server" Text='<%# Bind("interested_in") %>'>
  156.                                 </asp:TextBox><br />
  157.                                 email_id:
  158.                                 <asp:TextBox ID="email_idTextBox" runat="server" Text='<%# Bind("email_id") %>'>
  159.                                 </asp:TextBox><br />
  160.                                 <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
  161.                                     Text="Insert">
  162.                                 </asp:LinkButton>
  163.                                 <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
  164.                                     Text="Cancel">
  165.                                 </asp:LinkButton>
  166.                             </InsertItemTemplate>
  167.                             <ItemTemplate>
  168.                                 user_id:
  169.                                 <asp:Label ID="user_idLabel" runat="server" Text='<%# Eval("user_id") %>'></asp:Label><br />
  170.                                 first_name:
  171.                                 <asp:Label ID="first_nameLabel" runat="server" Text='<%# Bind("first_name") %>'>
  172.                                 </asp:Label><br />
  173.                                 last_name:
  174.                                 <asp:Label ID="last_nameLabel" runat="server" Text='<%# Bind("last_name") %>'></asp:Label><br />
  175.                                 gender:
  176.                                 <asp:Label ID="genderLabel" runat="server" Text='<%# Bind("gender") %>'></asp:Label><br />
  177.                                 date_of_birth:
  178.                                 <asp:Label ID="date_of_birthLabel" runat="server" Text='<%# Bind("date_of_birth") %>'>
  179.                                 </asp:Label><br />
  180.                                 birth_place:
  181.                                 <asp:Label ID="birth_placeLabel" runat="server" Text='<%# Bind("birth_place") %>'>
  182.                                 </asp:Label><br />
  183.                                 birth_time:
  184.                                 <asp:Label ID="birth_timeLabel" runat="server" Text='<%# Bind("birth_time") %>'>
  185.                                 </asp:Label><br />
  186.                                 city:
  187.                                 <asp:Label ID="cityLabel" runat="server" Text='<%# Bind("city") %>'></asp:Label><br />
  188.                                 state:
  189.                                 <asp:Label ID="stateLabel" runat="server" Text='<%# Bind("state") %>'></asp:Label><br />
  190.                                 zipcode:
  191.                                 <asp:Label ID="zipcodeLabel" runat="server" Text='<%# Bind("zipcode") %>'></asp:Label><br />
  192.                                 country:
  193.                                 <asp:Label ID="countryLabel" runat="server" Text='<%# Bind("country") %>'></asp:Label><br />
  194.                                 profession:
  195.                                 <asp:Label ID="professionLabel" runat="server" Text='<%# Bind("profession") %>'>
  196.                                 </asp:Label><br />
  197.                                 relation_status:
  198.                                 <asp:Label ID="relation_statusLabel" runat="server" Text='<%# Bind("relation_status") %>'>
  199.                                 </asp:Label><br />
  200.                                 languages:
  201.                                 <asp:Label ID="languagesLabel" runat="server" Text='<%# Bind("languages") %>'></asp:Label><br />
  202.                                 belongs_to:
  203.                                 <asp:Label ID="belongs_toLabel" runat="server" Text='<%# Bind("belongs_to") %>'>
  204.                                 </asp:Label><br />
  205.                                 interested_in:
  206.                                 <asp:Label ID="interested_inLabel" runat="server" Text='<%# Bind("interested_in") %>'>
  207.                                 </asp:Label><br />
  208.                                 email_id:
  209.                                 <asp:Label ID="email_idLabel" runat="server" Text='<%# Bind("email_id") %>'></asp:Label><br />
  210.                                 <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
  211.                                     Text="Edit">
  212.                                 </asp:LinkButton>
  213.                                 <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
  214.                                     Text="Delete">
  215.                                 </asp:LinkButton>
  216.                                 <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
  217.                                     Text="New">
  218.                                 </asp:LinkButton>
  219.                             </ItemTemplate>
  220.                         </asp:FormView>
  221.                         &nbsp;&nbsp;
  222.                     </ContentTemplate>
  223.                     <Triggers>
  224.                         <asp:AsyncPostBackTrigger ControlID="Button1"></asp:AsyncPostBackTrigger>
  225.                     </Triggers>
  226.                 </asp:UpdatePanel>
  227.                 &nbsp;
  228.             </ContentTemplate>
  229.         </cc1:TabPanel>
  230.         <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
  231.         </cc1:TabPanel>
  232.     </cc1:TabContainer>
  233. </asp:Content>
and here is my VB file

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OleDb
  2. Imports System.Data
  3. Imports System
  4. Imports System.Globalization
  5. Partial Class Testing
  6.     Inherits System.Web.UI.Page
  7.     Dim con As OleDbConnection
  8.     Dim cmd As OleDbCommand
  9.     Dim da As OleDbDataAdapter
  10.     Dim param As OleDbParameter
  11.     Dim ds As DataSet
  12.     Dim DTF As DateTimeFormatInfo
  13.     Dim dob As DateTime
  14.     Dim updatestr As String
  15.  
  16.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  17.         Response.Write(Me.FormView1.ClientID.ToString)
  18.     End Sub
  19.  
  20.     Protected Sub Button1C(ByVal sender As Object, ByVal e As System.EventArgs)
  21.         Me.FormView1.Visible = True
  22.         Me.FormView1.DataBind()
  23.         Call displayform()
  24.     End Sub
  25.     Sub displayform()
  26.  
  27.         con = New OleDbConnection()
  28.         con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & HttpContext.Current.Server.MapPath("sandesh.mdb")
  29.         cmd = New OleDbCommand("select * from [general] where user_id=@USERID", con)
  30.         con.Open()
  31.         param = New OleDbParameter("USERID", OleDbType.VarChar, 20)
  32.         cmd.Parameters.Add(param)
  33.         param.Value = "pankajsingh5k"
  34.         da = New OleDbDataAdapter(cmd)
  35.         'da.MissingSchemaAction = MissingSchemaAction.AddWithKey
  36.         ds = New DataSet
  37.         'da.FillSchema(ds, SchemaType.Source, "general")
  38.         da.Fill(ds, "General")
  39.         con.Close()
  40.         FormView1.DataSource = ds.Tables(0)
  41.         FormView1.DataBind()
  42.         If FormView1.CurrentMode = FormViewMode.Edit Then
  43.             Call populateYear()
  44.         End If
  45.     End Sub
  46.  
  47.     Protected Sub FormView1_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewModeEventArgs) Handles FormView1.ModeChanging
  48.         If e.NewMode = FormViewMode.Edit Then
  49.             FormView1.ChangeMode(e.NewMode)
  50.         ElseIf e.NewMode = FormViewMode.ReadOnly Then
  51.             FormView1.ChangeMode(e.NewMode)
  52.             Session("u") = 0
  53.         End If
  54.         Call displayform()
  55.     End Sub
  56.     Sub populateYear()
  57.  
  58.         ' find controls for day,month,year
  59.         Dim Year, month, day As DropDownList
  60.         Year = CType(FormView1.FindControl("dob_year"), DropDownList)
  61.         month = CType(FormView1.FindControl("dob_month"), DropDownList)
  62.         day = CType(FormView1.FindControl("dob_day"), DropDownList)
  63.  
  64.         'add years to the year DropDownLIst dynamically
  65.         For i As Integer = 1940 To 1991
  66.             Year.Items.Add(New ListItem(i.ToString))
  67.         Next
  68.  
  69.         'find the column that contains the date of birth as datetime
  70.         dob = CType(ds.Tables(0).Rows(0)("date_of_birth"), DateTime)
  71.  
  72.         ' Creates and initializes a DateTimeFormatInfo associated with the en-US culture
  73.         DTF = New CultureInfo("fr-FR", False).DateTimeFormat
  74.  
  75.         'assigning values
  76.         Year.SelectedValue = dob.Year
  77.         month.SelectedIndex = dob.Month - 1 'since there indexes start from 0
  78.         day.SelectedValue = dob.Day
  79.  
  80.  
  81.     End Sub
  82.     Sub edit()
  83.         Dim dt As Date
  84.  
  85.         Dim Year, month, day, gender, relation, belongs_to As DropDownList
  86.               Year = CType(FormView1.FindControl("dob_year"), DropDownList)
  87.         month = CType(FormView1.FindControl("dob_month"), DropDownList)
  88.         day = CType(FormView1.FindControl("dob_day"), DropDownList)
  89.         'gender = CType(FormView1.FindControl("gender_DDList"), DropDownList)
  90.         'relation = CType(FormView1.FindControl("relation_DDList"), DropDownList)
  91.         'belongs_to = CType(FormView1.FindControl("belongs_to_DDList"), DropDownList)
  92.         'Create a new DateTime object
  93.         dt = New DateTime(Year.SelectedValue, month.SelectedValue, day.SelectedValue)
  94.  
  95.  
  96.  
  97.         Dim updatecmd As New OleDbCommand()
  98.         updatestr = "update [general] set date_of_birth ='" & dt & "' where user_id='pankajsingh5k'"
  99.  
  100.         MsgBox(updateStr)
  101.         Try
  102.             con = New OleDbConnection()
  103.             con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & HttpContext.Current.Server.MapPath("sandesh.mdb")
  104.             con.Open()
  105.             updatecmd = New OleDbCommand(updatestr, con)
  106.             updatecmd.ExecuteNonQuery()
  107.             con.Close()
  108.         Catch ex As Exception
  109.  
  110.         End Try
  111.         FormView1.ChangeMode(FormViewMode.ReadOnly)
  112.         Call displayform()
  113.     End Sub
  114.  
  115.  
  116.     Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs)
  117.         Call edit()
  118.     End Sub
  119.     Private Sub loadscript()
  120.         Dim cs As ClientScriptManager = Page.ClientScript
  121.         Dim sb As StringBuilder = New StringBuilder
  122.         sb.Append("<script language='javascript'>")
  123.         sb.Append("function clientActiveTabChanged(sender, args) {")
  124.         sb.Append("var isTab2Loaded = $get('ctl00_middleContent_TabContainer1_TabPanel2_FormView1');")
  125.         sb.Append(" if(!isTab2Loaded && sender.get_activeTabIndex() == 1){")
  126.         sb.Append("__doPostBack('Button1', '');")
  127.         sb.Append("}")
  128.         sb.Append("}")
  129.         sb.Append("</script>")
  130.  
  131.         If (Not cs.IsClientScriptBlockRegistered("TAB")) Then
  132.             cs.RegisterClientScriptBlock(Me.GetType, "TAB", sb.ToString())
  133.  
  134.         End If
  135.  
  136.     End Sub
  137.  
  138.     Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
  139.         Call loadscript()
  140.     End Sub
  141. End Class
  142.  
if you want to know anything plz ask me...
thanks for ur time
Feb 18 '09 #1
Share this Question
Share on Google+
2 Replies


P: 8
Dear all,

i did some research at home and found out that the client script which i register at prerender works when i placed some alert("any message") in them but the __doPostBack() line doesnt work and thus the post back doesnt happen....

so please can anyone look tell me whether i am using the __doPOstBack in the wrong way...or whether it doesnt find the button or the arguments are wrong

when i run the page IE also sometimes tell errors in scripts...
Feb 19 '09 #2

acoder
Expert Mod 15k+
P: 16,027
This seems more of an ASP.NET problem. ASP.NET code is not much use in this forum. Post client-side versions of code in this forum.
Feb 23 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.