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.as px.vb 34 13
Help
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
Help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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....
I have a button control on the contact page - whenever I click on it it doesn't fire....
ASKER
here's the simple events
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("thankyo u.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"
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("thankyo
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
Otherwise, post your contact page html code so I can help
ASKER
here's the code
<%@ Page Language="VB" MasterPageFile="~/template s/English. master" CodeFile="Contact.aspx.vb" Inherits="en_Contact" title="TradMil | Les Traductions du Millénaire :: Contact Us" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphM ain" 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.co m<br>
</A>
<asp:validationsummary id="svContactForm" runat="server"></asp:valid ationsumma ry><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:RequiredFieldValidato r runat="server" ControlToValidate="txtName " ErrorMessage="Name is required" ID="rfvName">*</asp:Requir edFieldVal idator>
</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:ListI tem>
<asp:ListItem Value="Business">Business< /asp:ListI tem>
<asp:ListItem Value="Other">Other</asp:L istItem>
</asp:RadioButtonList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Literal runat="server" Text="Other - Please specify " ID="ltlOther"></asp:Litera l>
<asp:TextBox runat="server" ID="txtOtherType"></asp:Te xtBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<br>
Your E-mail:<br>
<asp:TextBox runat="server" ID="txtEmail"></asp:TextBo x>
<asp:RequiredFieldValidato r runat="server" ControlToValidate="txtEmai l" ErrorMessage="Email is required" ID="rfvEmail">*</asp:Requi redFieldVa lidator>
<br>
<br>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Select which service you would like 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="ddlDepa rtment"
ErrorMessage="Select which service you would like to contact" ID="cvService">*</asp:Comp areValidat or>
<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:Text Box>
<asp:RequiredFieldValidato r runat="server" ControlToValidate="txtMess age" ErrorMessage="Enter your message"
ID="rfvMessage">*</asp:Req uiredField Validator>
</asp:TableCell>
</asp:TableRow>
</asp:table></font></p>
<asp:imagebutton id="ibtnSend" runat="server" ImageUrl="~/images/send.gi f" CausesValidation="False" OnClientClick="ibtnSend_Cl ick"></asp :imagebutt on>
</div>
</asp:Content>
<%@ Page Language="VB" MasterPageFile="~/template
<asp:Content ID="Content1" ContentPlaceHolderID="cphM
<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.
</A>
<asp:validationsummary id="svContactForm" runat="server"></asp:valid
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:RequiredFieldValidato
</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 Value="Business">Business<
<asp:ListItem Value="Other">Other</asp:L
</asp:RadioButtonList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Literal runat="server" Text="Other - Please specify " ID="ltlOther"></asp:Litera
<asp:TextBox runat="server" ID="txtOtherType"></asp:Te
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<br>
Your E-mail:<br>
<asp:TextBox runat="server" ID="txtEmail"></asp:TextBo
<asp:RequiredFieldValidato
<br>
<br>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Select which service you would like 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="ddlDepa
ErrorMessage="Select which service you would like to contact" ID="cvService">*</asp:Comp
<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:Text
<asp:RequiredFieldValidato
ID="rfvMessage">*</asp:Req
</asp:TableCell>
</asp:TableRow>
</asp:table></font></p>
<asp:imagebutton id="ibtnSend" runat="server" ImageUrl="~/images/send.gi
</div>
</asp:Content>
ASKER
The control in question is:
<asp:imagebutton id="ibtnSend" runat="server" ImageUrl="~/images/send.gi f" CausesValidation="False" OnClientClick="ibtnSend_Cl ick"></asp :imagebutt on>
At the bottom of the code
<asp:imagebutton id="ibtnSend" runat="server" ImageUrl="~/images/send.gi
At the bottom of the code
the button is "ibtnSend", if "yes", change OnClientClick="ibtnSend_Cl ick" to OnClick="ibtnSend_Click"
Use OnClick="ibtnSend_Click" instead of OnClientClick="ibtnSend_Cl ick"
ASKER
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.ImageClickEv entArgs) Handles ibtnSend.Click
Response.Redirect("test.as px")
End Sub
End Class
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.ImageClickEv
Response.Redirect("test.as
End Sub
End Class
ASKER
How about I just paste the vb code
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Configuration.Confi gurationMa nager
Partial Class en_Contact
Inherits System.Web.UI.Page
#Region "Declaration"
Dim objConn As New SqlConnection(Configuratio nSettings. AppSetting s("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("imgHea der")
Dim b As Image = Master.FindControl("imgSub Header")
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).Vis ible = False
'set the page Sub heading
'pageSubHeading = "Deployment Schedule"
'RetrieveScheduledDeployme nts()
End If
End Sub
Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEv entArgs) Handles ibtnSend.Click
Dim Msg As MailMessage = New MailMessage()
Dim MailObj As New SmtpClient(CStr(AppSetting s("SmtpSer ver")))
Msg.From = New MailAddress(CStr(AppSettin gs("Contac tFromEmail ")))
Msg.To.Add(New MailAddress(CStr(AppSettin gs("Contac tToEmail") )))
Msg.IsBodyHtml = "False"
Msg.Body = "this is the Email body"
Msg.Subject = "This is the Subject"
MailObj.Send(Msg)
Response.Redirect("thankyo u.aspx")
End Sub
Private Sub rblRequestType_SelectedInd exChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rblRequestType.SelectedInd exChanged
If rblRequestType.SelectedVal ue = "Other" Then
tblContactForm.Rows(2).Vis ible = True
Else
tblContactForm.Rows(2).Vis ible = False
End If
End Sub
Private Sub InitializeComponent()
End Sub
End Class
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Configuration.Confi
Partial Class en_Contact
Inherits System.Web.UI.Page
#Region "Declaration"
Dim objConn As New SqlConnection(Configuratio
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("imgHea
Dim b As Image = Master.FindControl("imgSub
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).Vis
'set the page Sub heading
'pageSubHeading = "Deployment Schedule"
'RetrieveScheduledDeployme
End If
End Sub
Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEv
Dim Msg As MailMessage = New MailMessage()
Dim MailObj As New SmtpClient(CStr(AppSetting
Msg.From = New MailAddress(CStr(AppSettin
Msg.To.Add(New MailAddress(CStr(AppSettin
Msg.IsBodyHtml = "False"
Msg.Body = "this is the Email body"
Msg.Subject = "This is the Subject"
MailObj.Send(Msg)
Response.Redirect("thankyo
End Sub
Private Sub rblRequestType_SelectedInd
If rblRequestType.SelectedVal
tblContactForm.Rows(2).Vis
Else
tblContactForm.Rows(2).Vis
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.ImageClickEv entArgs) Handles ibtnSend.Click
Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEv
ASKER
it does bring me to Protected Sub ibtnSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEv entArgs) Handles ibtnSend.Click
however it doesn't fire up
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.
ASKER
Yes I am
I just uploaded the page - check it for yourself at:
http://www.tradmil.com/en/Contact.aspx
I just uploaded the page - check it for yourself at:
http://www.tradmil.com/en/Contact.aspx
ASKER
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.
ASKER
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.
ASKER
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
That's the reason why I posted both the HTML and VB code of the .aspx file
I don't understand
ASKER
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
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?
Public Sub ChangeImage(imagePath As String)
imgcontact_header.ImageUrl
End Sub
Then use it in your contact page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Master.ChangeImage("contac
End Sub
Your contact page should also include a MasterType directive in it.
<%@ MasterType VirtualPath="~/template.ma