Click here to Skip to main content
15,886,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Ok so I have a page which uses URL routing and has multiple panels. Some of the panels are to show default content while some panel become visible based upon URL requested (default content + extra content).
So the default content(eg: http.../Home) contains a trigger button for the modal, and two panels containing images and some text.

So when I load the default page (ie https..../Home) everything works fine, modal trigger works perfectly and images get shown as they should.

BUT if I request a different URL (http.../Home/abc --> which is handled by url routing) All the content panels (default content + extra content) becomes visible but images do not show up instead I get a broken image icon(even the image which is visible on default page becomes an broken image icon) and the modal trigger also does not work. Nothing happens if I click on it.

All the code is in one page still it doesnt work I cant figure out whats wrong...Specially with images, images are linked to an external http link which does work upon clicking the broken-image icons so something is going there but not the image?

here is the code for c#:

C#
protected void Page_Load(object sender, EventArgs e)
        {
                string clientname;
                if (GetRouteUrl(RouteData.Values["name"]) == null || RouteData.Values["name"] == null)
                {
                    // invalid info/ page
                }
                else 
                {
                    clientname = RouteData.Values["name"].ToString();
                
                if (clientname == "abc")
                {
                    Panel_2.Visible = true;
                    Panel_logo2.Visible = true;
                }
                else if (clientname == "xyz")
                {

                    Panel_1.Visible = true;
                    Panel_logo1.Visible = true;
                }
                else
                {
                    // invalid page/info
                }
                }
                }



code in the aspx:


<form id="form1" runat="server" >
         <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager> 

        <!-- Container for logos -->
       <div class="container">
            <div class="row">
                <div class="col">
                     <a href="http....../">  <img src="logo/default_logo" class="rounded float-left" height="100" width="200"/>  </a>
                </div>
                <div class="col-6 text-center">
                    <h1> stuff </h1>
                </div>

                <!-- abc  logo -->
                <div class="col">
                    <asp:Panel ID="Panel_logo1" runat="server" Visible="false">
                        <a href="http..."> <img src="logo/1" class="rounded float-right" height="100" width="200" />  </a>
                    </asp:Panel>

                    <!-- xyz logo  -->
                    <asp:Panel ID="Panel_logo2" runat="server" Visible="false">
                        <a href="https...."><img src="logo/2" class="rounded float-right" height="100" width="200"/>  </a>
                    </asp:Panel>
                    
                </div>
            </div>
        </div>

        <!-- End of Containers for logo -->

        

         <!-- Default section -->
         <div class="container">
             <div class="jumbotron">
                 <div class="col">
                     <p> some default stuff which shows up at all times</p>
                     <p>
                         more stuff
                     </p>

                    </div>
             </div>
         </div>

        
         <!-- abc -->
         <asp:Panel ID="Panel_abc" runat="server" Visible="false">
        <div class="container">
            <div class="jumbotron">
            <div class="col">
                <h1> ABC section</h1>
                <p> Section for message of ABC </p>
         </div>
         </div>
            </div>
        </asp:Panel>
             

         <!-- xyz-->
         <asp:Panel ID="Panel_xyz" runat="server" Visible="false">
            <div class="container">
                <div class="jumbotron">
                <div class="col">
                    <h1>XYZ Section</h1>
                    <p> Section for message of XYZ</p>
                    </div>
                    </div>
            </div>
            </asp:Panel>

        <!-- END -->

         <div class="container">
             <div class="row">
                    <div class=" col-sm-12 col-md-4">
                         <div class="card">
                             <div class="card-body">
                                 <p>stuff </p>
                                
                                 
                                 <!-- Button to trigger Login modal -->
                               
                                 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#logger_modal">
                                    Modal Trigger
                                  </button> 
                             </div>
                         </div>
                     </div>
                     <div class="col">
                     </div>
                 </div>
             </div>


         <!--Modal code-->
        <div class="modal fade" id="logger_modal" tabindex="-1" role="dialog" aria-labelledby="logger_model1" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h6 class="modal-title" id="logger_modal1">Please provide the required credientials to Log In.</h6>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true"</span>
                </button>
              </div>
                
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <div class="modal-body align-content-center">
                            <asp:TextBox ....onkeydown="return (event.keyCode!=13);"></asp:TextBox>
                            <asp:RequiredFieldValidator... EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
                            <br />
                            <asp:TextBox...onkeydown="return (event.keyCode!=13);"></asp:TextBox>
                            <asp:RequiredFieldValidator...EnableClientScript="false" Display="Dynamic"></asp:RequiredFieldValidator>
                            </br> <asp:Label ID="Label1" runat="server" Class="alert"></asp:Label>
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="..." />
                    </Triggers>
                       
                </asp:UpdatePanel>
                    
              <div class="modal-footer">
                  ............
              </div>
            </div>
          </div>
        </div>
             
         

    </form>


What I have tried:

<asp:Button class="btn btn-primary " ID="Modal_trigger" runat="server" Text="Login" data-toggle="modal" data-target="#logger-modal" OnClick="Modal_trigger_Click"/>


inside Modal_trigger_Click() method I call the java script function--> to display the modal modal.("show");
but the button itself doesnt work in this case even on the default page.
Posted
Updated 4-Sep-18 22:42pm
Comments
Bryian Tan 4-Sep-18 22:59pm    
By the way, is this a typos data-target="#logger-modal"? should that be data-target="#logger_modal" ?
Member 13973078 5-Sep-18 0:31am    
hmmm..I re-wrote that part of code (I had removed it before making this post) and made sure I keep the spellings same this time, but nothing happens.One more thing I tried is while on this asp button, I put a breakpoint and came to know that:-
- if I am on default page, when I click on asp button, the OnClick code breakpoint is reached and the modal is actually open in the browser but only till I click 'continue' and move ahead the breakpoint. So It opens but instantly closes
- if I am on one of the other URL`s (http...home/abc) the modal doesnt even open!, breakpoint is hit but nothing happens.

ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);

and the script:
<script type="text/javascript">
    function openModal() {
        $('#logger_modal').modal('show');
    }
</script>
dan!sh 5-Sep-18 2:01am    
Do you see something in Developer options -> Console when you load the page?
dan!sh 5-Sep-18 12:31pm    
No, in the browser. Press F12 once you have opened the faulty page and refresh the page to see if there are any errors in Console tab in browser.
Member 13973078 6-Sep-18 19:32pm    
ok, Ya I get errors there..
i was getting these errors first:
-GET http://localhost:50866/Page/Scripts/jquery.min.js 404 (Not Found)
-abc:213 GET http://localhost:50866/Page/Scripts/popper.min.js 404 (Not Found)
-abc:215 GET http://localhost:50866/Page/Scripts/bootstrap.min.js 404 (Not Found)
-abc:12 Uncaught ReferenceError: $ is not defined    
at openModal (abc:12)    
at abc:212openModal 
@ abc:12(anonymous) 
@ abc:212revq:212 
-GET http://localhost:50866/Page/Scripts/jquery.min.js 404 (Not Found)revq:213 
-GET http://localhost:50866/Page/Scripts/popper.min.js 404 (Not Found)revq:215 
-GET http://localhost:50866/Page/Scripts/bootstrap.min.js 404 (Not Found)


so used the PageresolveURL and it started to find these files but now it shows other errors:
-GET http://localhost:50866/Scripts/jquery.min.js%3E 404 (Not Found)
-Uncaught ReferenceError: $ is not defined    
at openModal (abc:14)    
at abc:214openModal
 @ abc:14(anonymous) 
@ abc:214
-GET http://localhost:50866/Scripts/jquery.min.js%3E 404 (Not Found)  abc:240
-Uncaught SyntaxError: Unexpected token export      popper.min.js:4-util.js:56 Uncaught TypeError: Cannot read property 'fn' of undefined    
at util.js:56    
at util.js:10    
at bootstrap.min.js:6    
at bootstrap.min.js:6(anonymous) 
@ util.js:56(anonymous) 
@ util.js:10(anonymous) 
@ bootstrap.min.js:6(anonymous) 
@ bootstrap.min.js:6


and also the login button (simple button not the asp:button) has stopped functioning at this stage even on the default page. It works perfectly(only on default page) without the Page.resolveURL in the scripts src

1 solution

<img src="logo/default_logo"


This is a relative url, it means look in a folder called logo at the current page level, so on "/" it looks in "/logo/", but on "/abc" it looks in "/abc/logo"

Google Page.ResolveURL to find out how to ensure a url is always right no matter the page it is on.
 
Share this answer
 
Comments
Member 13973078 5-Sep-18 11:56am    
I will surely check that and get back to you..
Member 13973078 6-Sep-18 18:00pm    
okey so I read about the Page.ResolveURL and Clienturl, I didnt knew about that..and this does solve the problem I was having with the images(logo`s) not showing up.
this is the code I have now, instead of jut providing the path to the logo file I use the Page.ResolveURL and ~ to get the path for "img src" from the root of my project and not from the page its written on.
<img src="<%= Page.ResolveUrl("~/logo/default_logo")%>" class="rounded float-left" height="100" width="200"/> 

thanks- 'F-ES Sitecore' for making me learn one more thing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900