Link to home
Start Free TrialLog in
Avatar of yaney00074
yaney00074

asked on

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
 
ASKER CERTIFIED SOLUTION
Avatar of bsdotnet
bsdotnet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mppeters
mppeters

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" %>
Avatar of yaney00074

ASKER

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

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

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

I just uploaded the page - check it for yourself at:
http://www.tradmil.com/en/Contact.aspx
Visual Web Developer 2005 Express Edition - to be more specific
think your button is not enabled. Check the properties of the button: guess "Enabled" is false now.
I just looed at it, actually enabled is "True"
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.
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
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
Any particular code in Master template?