?
Solved

Viewstate issue when loading user controls dynamically

Posted on 2010-03-25
8
Medium Priority
?
461 Views
Last Modified: 2013-11-07
I have an .aspx file that I load different user controls onto depending on what link the user clicks on. I have everything working just fine at this point. Please see the following question for reference:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_25275657.html
I came across an issue and needed to add some javascript to one of my user controls, this is where I discovered an even bigger problem:

When I view source on the page with one of my user controls, I don't see the current user control at all. I did some checking and found a post where someone had written a similar project that the "view source" DID show the correct user control.(http://www.aspnet4you.com/Articles.aspx?ArticleID=5032) I did some testing and found that if I put the following line in my web.config:
<xhtmlConformance mode="Legacy"/>
the "view source" showed correctly. After googleing to see what exactly this line did:
http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx
I found that it wasn't a good fix at all. My update panels do NOT work correctly.
After some consideration, the project I named above was written in framework 2.0(I upgraded when I ran it on my machine), my project is framework 3.5.

Does anyone know how to get my framework 3.5 project to render the viewstate properly(as it used to in framework 2.0)?
0
Comment
Question by:leyl
  • 5
  • 3
8 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 28704769
>When I view source on the page with one of my user controls, I don't see the current user control at all.

Do you mean that your control shows in the page but does not appear in the HTML view?  Or do you mean that it doesn't show in the viewstate...  If you mean the latter, how do you know that it doesn't appear in the viewstate?
0
 

Author Comment

by:leyl
ID: 28706112
Thank you very much for your response.
Nothing within the user control appears in the HTML view.
I tried to put a small javascript function within the user control and it threw an error, so I viewed the source from the browser and realized that none of the user control was there.
I would not have realized this if it wasn't for the javascript, because everything else works fine. I am able to see everything I need from the code behind on post back.
I wasn't sure if this was a "viewstate" issue or not. I just know that the HTML is not being rendered correctly some how.

Thanks again
0
 

Author Comment

by:leyl
ID: 28707950
Let me clarify a little:

The rendered page is fine(UI), when I right click and select "View Source", I do not see any of the html(static, or otherwise) that exists within the user control.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 38

Expert Comment

by:PaulHews
ID: 28708250
If the user control is showing in the browser window it has to be rendered in the source.  It's possible that you are searching using the ID that you gave it in Visual Studio, but the ASP.NET engine will render a new ID that will be quite different.
0
 

Author Comment

by:leyl
ID: 28709842
I have attached a screen shot, the html code for the user control, and the txt file from "View Source"

Below is the .aspx page html. I took out all databinding and tried to make it simple.

<form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
    <ContentTemplate>
    <div style="text-align:center;">
        <table border="0" cellpadding="0" cellspacing="0" width="890px">
            <tr>
                <td style="padding-left:25px;">
                    <cc2:C1TabStrip ID="TabStripMain" runat="server" Width="890px" VisualStyle="Office2007Blue" Alignment="Left" AutoPostBack="true">
                        <Tabs>
                            <cc2:C1Tab ID="tabContact" runat="server" Text="Contact Information"></cc2:C1Tab>
                            <cc2:C1Tab ID="tabConsent" runat="server" Text="Informed Consent"></cc2:C1Tab>
                            <cc2:C1Tab ID="tabNew" runat="server" Text="New Test"></cc2:C1Tab>
                        </Tabs>
                    </cc2:C1TabStrip>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:PlaceHolder ID="hold" runat="server"></asp:PlaceHolder>
                </td>
            </tr>
        </table>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ContactInformation.ascx.vb" Inherits="DynamicTest.ContactInformation" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<script language="javascript" type="text/javascript">
    function ShowHidePrefer(phoneType) {
        var chk = 'chkPrefer' + phoneType + 'Phone';
        var tr = 'trPrefer' + phoneType + 'Phone';
        if (document.getElementById(preId + chk).checked) {
            document.getElementById(preId + tr).style.display = 'inline';
        }
        else {
            document.getElementById(preId + tr).style.display = 'none';
        }
    }
    function SetColumns() {
        alert(document.getElementById('txtNumPregnancies'));
    }
</script>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table border="0" cellpadding="0" cellspacing="0">
    <tr valign="top" style="padding-top:10px;">
        <td align="left">
            <table border="0" cellpadding="2" cellspacing="0">
                <tr>
                    <td align="right">FIRST NAME:</td>
                    <td>
                        <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right">PREFERRED NAME:</td>
                    <td>
                        <asp:TextBox ID="txtPreferred" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right">MIDDLE NAME or INITIAL:</td>
                    <td>
                        <asp:TextBox ID="txtMiddleName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right">LAST NAME:</td>
                    <td>
                        <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right">MAIDEN NAME:</td>
                    <td>
                        <asp:TextBox ID="txtMaidenName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right">PARTNER'S LAST NAME:</td>
                    <td>
                        <asp:TextBox ID="txtPartnerLastName" runat="server"></asp:TextBox>
                    </td>
                </tr>
            </table>
        </td>
        <td style="width:10px;">&nbsp;</td>
        <td align="center">
            <table border="0" cellpadding="2" cellspacing="0">
                <tr>
                    <td style="border-bottom:solid 1px black;"><b>Prefer</b></td>
                    <td colspan="3"><b>Phone Numbers</b></td>
                </tr>
                <tr>
                    <td style="width:50px;">
                        <asp:CheckBox ID="chkPreferHomePhone" runat="server" />
                    </td>
                    <td style="width:90px;text-align:right;">Home Phone:</td>
                    <td>
                        <asp:TextBox Id="txtHomePhone" runat="server" Width="75px"></asp:TextBox>
                        <ajax:MaskedEditExtender ID="meeHomePhone" runat="server" TargetControlID="txtHomePhone" MaskType="None" Mask="(999)999-9999"></ajax:MaskedEditExtender>
                    </td>
                    <td style="width:130px;text-align:left;">
                        <b>Ext.:</b><asp:TextBox ID="txtHomePhoneExt" runat="server" Width="50px"></asp:TextBox>
                    </td>
                </tr>
                <tr id="trPreferHomePhone" runat="server" style="display:none;">
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <asp:CheckBoxList ID="cblPreferHomePhone" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="812" Text="8-12am"></asp:ListItem>
                            <asp:ListItem Value="123" Text="12-3pm"></asp:ListItem>
                            <asp:ListItem Value="36" Text="3-6pm"></asp:ListItem>
                            <asp:ListItem Value="6" Text="After 6pm"></asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="chkPreferWorkPhone" runat="server" />
                    </td>
                    <td align="right">Work Phone:</td>
                    <td>
                        <asp:TextBox ID="txtWorkPhone" runat="server" Width="75px"></asp:TextBox>
                        <ajax:MaskedEditExtender ID="meeWorkPhone" runat="server" TargetControlID="txtWorkPhone" MaskType="None" Mask="(999)999-9999"></ajax:MaskedEditExtender>
                    </td>
                    <td align="left">
                        <b>Ext.:</b><asp:TextBox ID="txtWorkPhoneExt" runat="server" Width="50px"></asp:TextBox>
                    </td>
                </tr>
                <tr id="trPreferWorkPhone" runat="server" style="display:none;">
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <asp:CheckBoxList ID="cblPreferWorkPhone" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="812" Text="8-12am"></asp:ListItem>
                            <asp:ListItem Value="123" Text="12-3pm"></asp:ListItem>
                            <asp:ListItem Value="36" Text="3-6pm"></asp:ListItem>
                            <asp:ListItem Value="6" Text="After 6pm"></asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="chkPreferCellPhone" runat="server" />
                    </td>
                    <td align="right">Cell Phone:</td>
                    <td>
                        <asp:TextBox ID="txtCellPhone" runat="server" Width="75px"></asp:TextBox>
                        <ajax:MaskedEditExtender ID="meeCellPhone" runat="server" TargetControlID="txtCellPhone" MaskType="None" Mask="(999)999-9999"></ajax:MaskedEditExtender>
                    </td>
                    <td>&nbsp;</td>
                </tr>
                <tr id="trPreferCellPhone" runat="server" style="display:none;">
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <asp:CheckBoxList ID="cblPreferCellPhone" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="812" Text="8-12am"></asp:ListItem>
                            <asp:ListItem Value="123" Text="12-3pm"></asp:ListItem>
                            <asp:ListItem Value="36" Text="3-6pm"></asp:ListItem>
                            <asp:ListItem Value="6" Text="After 6pm"></asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                </tr>
                <tr valign="top">
                    <td>
                        <asp:CheckBox ID="chkPreferTextMessage" runat="server" />
                    </td>
                    <td colspan="3" align="left">Text Message<br />
                        <span style="font-size:8pt;">* Text messages will be used strictly for reminders,<br />not as a method of contact</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="chkPreferBeeperPhone" runat="server" />
                    </td>
                    <td align="right">Beeper:</td>
                    <td>
                        <asp:TextBox ID="txtBeeperPhone" runat="server" Width="75px"></asp:TextBox>
                        <ajax:MaskedEditExtender ID="meeBeeperPhone" runat="server" TargetControlID="txtBeeperPhone" MaskType="None" Mask="(999)999-9999"></ajax:MaskedEditExtender>
                    </td>
                    <td>&nbsp;</td>
                </tr>
                <tr id="trPreferBeeperPhone" runat="server" style="display:none;">
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <asp:CheckBoxList ID="cblPreferBeeperPhone" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="812" Text="8-12am"></asp:ListItem>
                            <asp:ListItem Value="123" Text="12-3pm"></asp:ListItem>
                            <asp:ListItem Value="36" Text="3-6pm"></asp:ListItem>
                            <asp:ListItem Value="6" Text="After 6pm"></asp:ListItem>
                        </asp:CheckBoxList>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr valign="top">
        <td>
            <asp:Panel ID="pnlAddresses" runat="server" Width="450px">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr style="height:20px;vertical-align:middle;font-weight:bold;background-color:#7ca492;">
                        <td align="center" style="font-size:10pt;">
                            Mailing Addresses
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <ajax:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="pnlAddresses" Enabled="true" Color="#7ca492" BorderColor="#7ca492" Corners="All" Radius="6">
            </ajax:RoundedCornersExtender>
        </td>
        <td style="width:10px;">&nbsp;</td>
        <td>
            <asp:Panel ID="pnlEmail" runat="server" Width="325px">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr style="height:20px;vertical-align:middle;font-weight:bold;background-color:#7ca492;">
                        <td align="center" style="font-size:10pt;">
                            Email Addresses
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <ajax:RoundedCornersExtender ID="RoundedCornersExtender2" runat="server" TargetControlID="pnlEmail" Enabled="true" Color="#7ca492" BorderColor="#7ca492" Corners="All" Radius="6">
            </ajax:RoundedCornersExtender>
        </td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
        <td>
            <asp:Panel ID="pnlSpecial" runat="server" Width="458px">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr style="height:20px;vertical-align:middle;font-weight:bold;background-color:#7ca492;">
                        <td align="center" style="font-size:10pt;">
                            Special Instructions
                        </td>
                    </tr>
                    <tr style="height:20px;vertical-align:middle;">
                        <td align="center" style="font-size:8pt;">
                            Are there any special instructions when trying to contact you<br />
                            or when leaving a message for you?
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <ajax:RoundedCornersExtender ID="RoundedCornersExtender3" runat="server" TargetControlID="pnlSpecial" Enabled="true" Color="#7ca492" BorderColor="#7ca492" Corners="All" Radius="6">
            </ajax:RoundedCornersExtender>
        </td>
        <td style="width:10px;">&nbsp;</td>
        <td>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td colspan="2">Did someone refer you to the Contraceptive CHOICE Project?</td>
                </tr>
                <tr>
                    <td>
                        <asp:RadioButtonList ID="rblRefer" runat="server" RepeatDirection="Horizontal">
                            <asp:ListItem Value="True" Text="Yes"></asp:ListItem>
                            <asp:ListItem Value="False" Text="No"></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td>
                        If yes, who: <asp:TextBox ID="txtReferWho" runat="server" Width="300px"></asp:TextBox>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr valign="top">
        <td>
            <asp:Panel ID="pnlContacts" runat="server" Width="452px">
                <table border="0" CellPadding="0" CellSpacing="0">
                    <tr style="height:20px;vertical-align:middle;font-weight:bold;background-color:#7ca492;">
                        <td align="center" style="font-size:10pt;">
                            Contacts
                        </td>
                    </tr>
                    <tr style="vertical-align:middle;">
                        <td align="center" style="font-size:8pt;padding:5px;">
                            We would like to ask you for contact information for individuals that<br />
                            would know how to reach you if we cannot reach you using the<br />
                            information you provided earlier.  This could be someone who does<br />
                            not live in your household but who would know how to contact you,<br />
                            for example a friend, or neighbor, or a family member.  As I told you<br />
                            earlier, this information will be kept strictly confidential and only<br />
                            used to help us contact you for study purposes.
                        </td>
                    </tr>
                    <tr>
                        <td align="left" style="font-size:8pt;padding:5px;">
                            <b>IF MARRIED/PARTNERED:</b> Ask for spouse/partner's first and last<br />
                            name, phone number and address.<br />
                            <b>IF A MINOR:</b> Ask for parent or guardian's first and last name,<br />
                            phone number and address.
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <ajax:RoundedCornersExtender ID="RoundedCornersExtender4" runat="server" TargetControlID="pnlContacts" Enabled="true" Color="#7ca492" BorderColor="#7ca492" Corners="All" Radius="6">
            </ajax:RoundedCornersExtender>
        </td>
        <td style="width:10px;">&nbsp;</td>
        <td align="center">
            <asp:Panel ID="pnlPhysicians" runat="server" Width="380px">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr style="height:20px;vertical-align:middle;font-weight:bold;background-color:#7ca492;">
                        <td align="center" style="font-size:10pt;">
                            Physicians
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size:8pt;padding:5px;">
                            What is the name of the doctor/health care provider<br />
                            or clinic name where you seek reproductive health (gynecologic) care?
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <ajax:RoundedCornersExtender ID="RoundedCornersExtender5" runat="server" TargetControlID="pnlPhysicians" Enabled="true" Color="#7ca492" BorderColor="#7ca492" Corners="All" Radius="6">
            </ajax:RoundedCornersExtender>
        </td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
        <td colspan="3">
            <asp:Button ID="btnSubmitPage" runat="server" Text="Submit Changes" />
        </td>
    </tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>

Open in new window

ScreenShot.gif
ViewSource.txt
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 28711163
I'm guessing that it's a feature of the c1tabcontrol and how it loads content dynamically.   It seems to be using AJAX to build the content, which explains why it doesn't show up in your source.  The real issue (the script error) might not be related.
0
 

Author Comment

by:leyl
ID: 28713187
Good thought.

It doesn't make sense to me because the user controls don't actually reside inside the tabstrip control. It must have a bunch of ajax compiled with it that messes other stuff up.
I replaced the tabstrip control with a dropdownlist and had no issue. I just wouldn't have thought that would be the problem.

Thank you so much for helping me with this. I truly appreciate it.
0
 

Author Comment

by:leyl
ID: 29132798
After much going back and forth, It was not the C1tabControl causing the problem, it is the UpdatePanel.
I have yet to find a real fix for this.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Native ability to set a user account password via AD GPO was removed because the passwords can be easily decrypted by any authenticated user in the domain. Microsoft recommends LAPS as a replacement and I have written an article that does something …
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question