ASP.NEt 2.0 - Changing MasterTemplate control value from contentPlaceholder

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
 
yaney00074Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bsdotnetCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mppetersCommented:
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" %>
0
yaney00074Author 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....
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

yaney00074Author 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"
0
bsdotnetCommented:
check your <asp:button> tag to see if "OnClick="Button1_Click" exists.

Otherwise, post your contact page html code so I can help
0
yaney00074Author 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>

0
yaney00074Author 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
0
bsdotnetCommented:
the button is "ibtnSend", if "yes", change OnClientClick="ibtnSend_Click" to OnClick="ibtnSend_Click"
0
bsdotnetCommented:
Use OnClick="ibtnSend_Click" instead of OnClientClick="ibtnSend_Click"
0
yaney00074Author Commented:
I just changed it - still not working
0
bsdotnetCommented:
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
0
yaney00074Author 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
0
bsdotnetCommented:
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
0
yaney00074Author 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
0
bsdotnetCommented:
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.
0
yaney00074Author Commented:
Yes I am

I just uploaded the page - check it for yourself at:
http://www.tradmil.com/en/Contact.aspx
0
yaney00074Author Commented:
Visual Web Developer 2005 Express Edition - to be more specific
0
bsdotnetCommented:
think your button is not enabled. Check the properties of the button: guess "Enabled" is false now.
0
yaney00074Author Commented:
I just looed at it, actually enabled is "True"
0
bsdotnetCommented:
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.
0
yaney00074Author 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
0
yaney00074Author 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
0
bsdotnetCommented:
Any particular code in Master template?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.