Solved

Updatepanels and user controls

Posted on 2010-09-13
22
424 Views
Last Modified: 2012-05-10
<asp:UpdatePanel ID="uptPnlMain" UpdateMode="Conditional" runat="server">
                    <ContentTemplate>
                        <table>
                            <tr style="padding-top: 7px">
                                <td>
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab">
                                        <div>
                                            <tr>
                                                <td width="979" align="left" valign="middle" class="pnav" style="padding-left: 15px;
                                                    padding-top: 5px; padding-right: 4px;">
                                                    <asp:LinkButton ID="lnkCorporate" runat="server" CausesValidation="false"
                                                        OnCommand="lnkCorporate_Command" Text="Corp ID   |"></asp:LinkButton>
                                                    <asp:LinkButton ID="lnkPersonal" runat="server" CausesValidation="false"
                                                        OnCommand="lnkPersonal_Command" Text="Personal  |"></asp:LinkButton>
&#9;&#9;&#9;&#9;&#9;&#9; </td>
                                            </tr>
                                        </div>
                                    </table>
&#9;&#9;&#9;    <tr id="trCorporateRow" visible="false" runat="server">
                                <td>
                                    <ucCorporate:CorpId ID="CorpIdTab" runat="server" />
                                </td>
                            </tr>
                            <tr id="trPersonalRow" visible="false" runat="server">
                                <td>
                                    <ucPersonal:Personal ID="PersonalTab" runat="server" />
                                </td>
                            </tr>

protected void lnkCorporate_Command(object sender, EventArgs e)
        {
&#9;&#9;trPersonalRow.Visible = true;
                trCorporateRow.Visible = false;
&#9;}

 protected void lnkPersonal_Command(object sender, EventArgs e)
        {
&#9;&#9;trPersonalRow.Visible = false;
                trCorporateRow.Visible = true;
&#9;}

There are two user controls,personal and corporate.
I have noticed one thing.By default I am loading Personal user control.
When I click corporate link,corporate user control is loaded.
but html is not changed.In the source I am having controls of personal tab only.
I tried using placeholder instead of using rows but sane thing happens.
I am assuming this is because of the Updatepanel,as before it was loading controls of the respective user control.
I am expecting some guidance from you experts.Please tell me what needs to be done?
0
Comment
Question by:johny_bravo1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 3
  • +3
22 Comments
 
LVL 7

Expert Comment

by:gsiric
ID: 33659992
Did you tried to hide or show controls not rows in a table ?
0
 
LVL 4

Expert Comment

by:antonybrahin
ID: 33660015
or u can put it in a div if more than one controls and do the hide and show.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660065
Not tried earlier,
but after your suggestion I tried putting
PersonalTab.Visible = true;
                CorpIdTab.Visible = false;

but html is not changing.
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660083
Controls are loaded.I can see the controls on the page.but when I see the source of that page,the controls are not present in the source
0
 
LVL 14

Accepted Solution

by:
existenz2 earned 250 total points
ID: 33660085
When using updatepanels you don't really see the HTML changing normally. But your code seems valid, so this should work.

Are you using any child updatepanels? Also have you tried to call "uptPnlMain.Update()" in the two events?
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660102
I tried uptPnlMain.Update() with no effect.
I need the changed html as I have to write some javasript functions there.
But when I write any,in document.getElementById i never found the control
0
 
LVL 14

Expert Comment

by:existenz2
ID: 33660118
But do you see it in the UI?
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660162
Yes in UI it is appearing but not when I look for the source
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660169
Yes in UI it is appearing but not when I look for the source
0
 
LVL 14

Expert Comment

by:existenz2
ID: 33660200
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 250 total points
ID: 33660207
You won't see the source for anything except what was displayed originaly. The update panel dynamically writes the relevant HTML to the borwser, the View Source option only shows the markup that was sent with the last full page reload.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660404
Okk.
but when I write a javascript function on the controls on second user control,it's not working.
As I am not getting that control,what should I do then?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33660446
Could you clarify "not working" a little? What isn't working, what is your javascript attempting to do?
0
 
LVL 14

Expert Comment

by:existenz2
ID: 33660461
They have probably different names because of the injection then you are expecting in your JS.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660524
I have checkbox in the second user control which copies current address to permanent address.
When I click the checkbox,I get "Error: Object expected" for javascript.
I put debugger in the function,but it is not reached even.
Without updatepanel,it works fine
Following is the javascript function.


function FillPermanent()
    {
    
        if(document.getElementById('chkCopy').checked)
        {
        var IndexValue = $get('<%=ddlLocalCountry.ClientID %>').selectedIndex;
        var SelectedVal = $get('<%=ddlLocalCountry.ClientID %>').options[IndexValue].value;
            
        var IndexValue1 = $get('<%=ddlLocalState.ClientID %>').selectedIndex;
        var SelectedVal1 = $get('<%=ddlLocalState.ClientID %>').options[IndexValue1].value;
       
        
        var IndexValue2 = $get('<%=ddlLocalCity.ClientID %>').selectedIndex;
        var SelectedVal2 = $get('<%=ddlLocalCity.ClientID %>').options[IndexValue2].value;
      
        
        document.getElementById('<%=txtPermArea.ClientID %>').value = document.getElementById('<%= txtLocalArea.ClientID %>').value;
        document.getElementById('<%=txtPermSubUrb.ClientID %>').value = document.getElementById('<%=txtLocalSubUrb.ClientID %>').value ;
        document.getElementById('<%=txtPermPIN.ClientID %>').value = document.getElementById('<%=txtLocalPIN.ClientID %>').value ;
        
       
        var behavior = $find('<%=CDDPermCountry.ClientID %>');
        behavior.set_SelectedValue(SelectedVal);
        behavior._onParentChange(null, true);
        
         var behavior1 = $find('<%=CCDPermState.ClientID %>');
        behavior1.set_SelectedValue(SelectedVal1);
        behavior1._onParentChange(null, true);
        
         var behavior2 = $find('<%=CDDPermCity.ClientID %>');
        behavior2.set_SelectedValue(SelectedVal2);
        behavior2._onParentChange(null, true);
}

Open in new window

0
 
LVL 14

Expert Comment

by:existenz2
ID: 33660712
If 'chkCopy' as an ASP.NET Checkbox it will have a different id, so it will return null. You will also need the ClientID from the checkbox in that case.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33660728
<input type="checkbox" id="chkCopy" name="chkCopy"    onclick="FillPermanent()" />
It's an html control
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33660737
Try changing the start of your javascript to:

    function FillPermanent( source )
        {
   
            if(source.checked)
           {


And your checkbox to:

    <input type="checkbox" id="chkCopy" name="chkCopy"    onclick="FillPermanent(this);" />
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 33671095
:( this is also not working.
Currently I have removed updatepanel and it is working fine.I am waiting from some solution.thanks
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 33772123
Try changing the LinkButton event to OnClick.  If that doesn't work try adding also adding Triggers to the UpdatePanel.

        <Triggers>
             <asp:AsyncPostBackTrigger ControlID="lnkCorporate" EventName="Click" />
             <asp:AsyncPostBackTrigger ControlID="lnkPersonal" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Panel>
0
 
LVL 8

Author Closing Comment

by:johny_bravo1
ID: 33901504
Thanks Experts
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Analysis 7 59
Cannot interpret token '"' at position 10. 3 25
msiexec won't run 4 33
How to send the email using C# with embedded HTML TABLE 3 25
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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