We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

ASP.NEt 2.0 - Changing MasterTemplate control value from contentPlaceholder

yaney00074
yaney00074 asked
on
Medium Priority
289 Views
Last Modified: 2010-05-18
Hi,
I have a web application built in ASP.NET 2.0 and VB.NET as core language.
I have a template.master file I used to build my page.
However I would like the template images to be chaged bynamically based on the loaded page.
That means,  whenever the the contact.aspx page is loaded I would like the contact_header.jpg to be displayed
same things applies with the home_header.jpg whenever the homepage is loaded.

I tried to work the trick around the code behing of each page, but with no success.

This is the error I get whenever I compile:
Error      2      'myNamespace.folderEnglish.Protected Dim WithEvents imgcontact_header As System.Web.UI.HtmlControls.HtmlImage' is not accessible in this context because it is 'Protected'.      D:\MyWebsite\en\Contact.aspx.vb      34      13


Help
 
Comment
Watch Question

Commented:
User <asp:image> instead of <img>

in page_load of contact.aspx.vb

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim a As Image = Master.FindControl("imgcontact_header")
        a.ImageUrl = "contact_header.jpg"
    End Sub

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
Either that or you could expose a public method in your Master page that would set the image.

Public Sub ChangeImage(imagePath As String)
  imgcontact_header.ImageUrl = imagePath
End Sub

Then use it in your contact page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  Master.ChangeImage("contact_header.jpg")
End Sub

Your contact page should also include a MasterType directive in it.
<%@ MasterType VirtualPath="~/template.master" %>

Author

Commented:
Yeah it looks like it works - however
I have a button control on the contact page - whenever I click on it it doesn't fire....

Author

Commented:
here's the simple events

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("thankyou.aspx")
    End Sub

For some strange reason, it just doesn't fire - or in other words, nothing happens - I am not redirected to "thankyou.pasx"

Commented:
check your <asp:button> tag to see if "OnClick="Button1_Click" exists.

Otherwise, post your contact page html code so I can help

Author

Commented:
here's the code

<%@ Page Language="VB" MasterPageFile="~/templates/English.master" CodeFile="Contact.aspx.vb" Inherits="en_Contact" title="TradMil | Les Traductions du Mill&eacute;naire :: Contact Us" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphMain" Runat="Server" AutoEventWireup="true">
    <div class="tah11" style="PADDING-RIGHT: 15px; PADDING-LEFT: 50px; PADDING-BOTTOM: 15px; COLOR: #4a4a4a; PADDING-TOP: 15px">
                  <p><strong>Canadian Head Office</strong><br>
                        2239 EGLINTON EAST
                        <br>
                        SUITE 217<br>
                        TORONTO, ONTARIO<br>
                        M1K 2N1</p>
                  <p>Tel. 416.752.93.35 | Fax. 416.752.93.35 | Email: <A href="mailto:info@TradMil.com">info@TradMil.com<br>
                        </A>
                        <asp:validationsummary id="svContactForm" runat="server"></asp:validationsummary><strong style="COLOR: #ff9832" autoeventwireup="true">For
                              questions and inquiries, please fill out the form below:</strong>
                        <BR>
                        <br>
                        <font style="COLOR: #8f8f8f">
                              <asp:table id="tblContactForm" runat="server" CssClass="tah11">
                                    <asp:TableRow>
                                          <asp:TableCell>
                              Your Name:<br>
                              <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtName" ErrorMessage="Name is required" ID="rfvName">*</asp:RequiredFieldValidator>
</asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                          <asp:TableCell>
                              <br>Inquiry Type:<br>
                              <asp:RadioButtonList runat="server" AutoPostBack="True" ID="rblRequestType">
                                                      <asp:ListItem Value="Personal">Personal</asp:ListItem>
                                                      <asp:ListItem Value="Business">Business</asp:ListItem>
                                                      <asp:ListItem Value="Other">Other</asp:ListItem>
                                                </asp:RadioButtonList>
</asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                          <asp:TableCell>
                                                <asp:Literal runat="server" Text="Other - Please specify " ID="ltlOther"></asp:Literal>
                                                <asp:TextBox runat="server" ID="txtOtherType"></asp:TextBox>
                                          </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                          <asp:TableCell>
                                          <br>
                                                Your E-mail:<br>
                                                      <asp:TextBox runat="server" ID="txtEmail"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtEmail" ErrorMessage="Email is required" ID="rfvEmail">*</asp:RequiredFieldValidator>
<br>
                                                      <br>
                                          </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                          <asp:TableCell>
                                          Select which service&nbsp;you would like&nbsp;to contact:<br>
                              <asp:DropDownList runat="server" ID="ddlDepartment">
                                                      <asp:ListItem Value="Select One..." Selected="True">Select One...</asp:ListItem>
                                                      <asp:ListItem Value="Billing Service">Billing Service</asp:ListItem>
                                                      <asp:ListItem Value="Translation Service">Translation Service</asp:ListItem>
                                                      <asp:ListItem Value="Information Service">Information Service</asp:ListItem>
                                                </asp:DropDownList>
<asp:CompareValidator runat="server" ValueToCompare="Select One..." Operator="NotEqual" ControlToValidate="ddlDepartment"
                                                      ErrorMessage="Select which service you would like to contact" ID="cvService">*</asp:CompareValidator>
<br>
                              <br>
                                          </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                          <asp:TableCell>
                                          Enter your comments, suggestions, questions below:
                              <asp:TextBox runat="server" Rows="6" TextMode="MultiLine" Columns="40" ID="txtMessage"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtMessage" ErrorMessage="Enter your message"
                                                      ID="rfvMessage">*</asp:RequiredFieldValidator>
</asp:TableCell>
                                    </asp:TableRow>
                              </asp:table></font></p>
                  <asp:imagebutton id="ibtnSend" runat="server" ImageUrl="~/images/send.gif" CausesValidation="False" OnClientClick="ibtnSend_Click"></asp:imagebutton>
        </div>
</asp:Content>

Author

Commented:
The control in question is:

<asp:imagebutton id="ibtnSend" runat="server" ImageUrl="~/images/send.gif" CausesValidation="False" OnClientClick="ibtnSend_Click"></asp:imagebutton>

At the bottom of the code

Commented:
the button is "ibtnSend", if "yes", change OnClientClick="ibtnSend_Click" to OnClick="ibtnSend_Click"

Commented:
Use OnClick="ibtnSend_Click" instead of OnClientClick="ibtnSend_Click"

Author

Commented:
I just changed it - still not working

Commented:
I notice your page header is showing: Inherits="en_Contact", thus, make sure Class name in your contact.aspx.vb is also "en_Contact".
If you double click ibtnSend, it should bring you to the code below.

Contact.aspx.vb
==========
Partial Class en_Contact
    Inherits System.Web.UI.Page

    Protected Sub ibtnSend_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnSend.Click
        Response.Redirect("test.aspx")
    End Sub
End Class

Author

Commented:
How about I just paste the vb code


Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Configuration.ConfigurationManager

Partial Class en_Contact
    Inherits System.Web.UI.Page

#Region "Declaration"

    Dim objConn As New SqlConnection(ConfigurationSettings.AppSettings("xDSN"))
    Dim contactEmailObj As ContactEmail
    'Dim EmailProc As EmailProcessor
    Dim messageObj As MailMessage
    'Dim imgHeader As HtmlControls.HtmlImage
    'Dim imageSubHeader As HtmlControls.HtmlImage

#End Region

#Region "Controls"

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then

            'set the page title
            'pageTitle = "TradMil | Les Traductions du Millenaire :: Contact Us"
            Dim a As Image = Master.FindControl("imgHeader")
            Dim b As Image = Master.FindControl("imgSubHeader")

            a.ImageUrl = "../images/hd_contact.jpg"
            b.ImageUrl = "../images/hr_cont.jpg"

            'set the page heading
            'pageHeading = "TradMil Data - Deployment Assistance Program"

            tblContactForm.Rows(2).Visible = False

            'set the page Sub heading
            'pageSubHeading = "Deployment Schedule"

            'RetrieveScheduledDeployments()

        End If

    End Sub


    Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnSend.Click

        Dim Msg As MailMessage = New MailMessage()
        Dim MailObj As New SmtpClient(CStr(AppSettings("SmtpServer")))

        Msg.From = New MailAddress(CStr(AppSettings("ContactFromEmail")))
        Msg.To.Add(New MailAddress(CStr(AppSettings("ContactToEmail"))))
        Msg.IsBodyHtml = "False"
        Msg.Body = "this is the Email body"
        Msg.Subject = "This is the Subject"

        MailObj.Send(Msg)

        Response.Redirect("thankyou.aspx")

    End Sub


    Private Sub rblRequestType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rblRequestType.SelectedIndexChanged
        If rblRequestType.SelectedValue = "Other" Then
            tblContactForm.Rows(2).Visible = True
        Else
            tblContactForm.Rows(2).Visible = False
        End If
    End Sub


    Private Sub InitializeComponent()

    End Sub

End Class

Commented:
there is always a risk when you paste code directly. If the code you paste is correct, when you double click ibtnSend in design view, it should bring you to
Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnSend.Click

Author

Commented:
it does bring me to Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnSend.Click
however it doesn't fire up

Commented:
are you using vs2005? have no clue why it's not working. I copies your code to vs2005 express and it's working. Have no clue.

Author

Commented:
Yes I am

I just uploaded the page - check it for yourself at:
http://www.tradmil.com/en/Contact.aspx

Author

Commented:
Visual Web Developer 2005 Express Edition - to be more specific

Commented:
think your button is not enabled. Check the properties of the button: guess "Enabled" is false now.

Author

Commented:
I just looed at it, actually enabled is "True"

Commented:
Or any part of your code disable the button? Your button looks like it's disabled or locked. It doesn't even allow clicking at all.

Author

Commented:
The Which part of my code.

That's the reason why I posted both the HTML and VB code of the .aspx file


I don't understand

Author

Commented:
I think it has something to to with master template....

The contact.aspx is created from the Englisg.Master Template...

I don't know if there is a way to fix it from there

Commented:
Any particular code in Master template?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.