<%# OutputCache Duration="10" VaryByParam="Button1" %>
I type the above code to vary text of Button but it does not vary the value .
VaryByParam refers to query string parameters. Not the value of buttons or other controls.
For example:
http://www.example.com/mypage.aspx?id=10
http://www.example.com/mypage.aspx?id=20
Would be cached separately if you set:
<%# OutputCache Duration="10" VaryByParam="id" %>
Related
I have a label on master page and need to parse the value of the label onto another page. I have set a public property for the label on the master page and I have also defined the virtual-path of the master page on the other page but i get the error "BC30002 type myprojectname.site1.master is not difined".
Please any help? below is my code
//this is the codebehind of my mastser page
Public Property userid As Label
Get
userid = Me.lbluserid()
Return userid
End Get
Set(value As Label)
userid.Text.ToString()
End Set
End Property
//this is my content page
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="proudctselection.aspx.vb"
MasterPageFile="~/Site1master.Master" Inherits="RANAMART.proudctselection" %>
<%# MasterType VirtualPath="~/Site1master.Master" %>
<asp:Content ID="rannamart" ContentPlaceHolderID="rannamart" runat="server">
//somthing goes here
</asp:Content>
if content type of page directive is not mentioned then what will be the default content type for page directive ??
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Page.aspx.cs" Inherits="Page" %>
in this case what is the value of ContentType ??
The default value is "text/html", as mentioned in the documentation for ContentType property:
The HTTP MIME type of the output stream. The default value is "text/html".
This is how a register the control on the page:
<%# Register TagPrefix="uc" TagName="Pcp" Src="../../Controls/ClientPayement.ascx" %>
And this is how I use it:
<uc1:Pcp ID = "pcpClient1"></uc1:Pcp>
I don't know why uc1 has a green underline warning. When I hover over it, it says: "Unrecognized namespace uc1". And the user control is not displaying on the page.
Am I missing something? Yet this tutorial says that this is all I need to do.
You are specifying a uc prefix in <%# Register TagPrefix="uc" .. so that's the one you should use:
<uc:Pcp ID = "pcpClient1"></uc:Pcp>
Or you could change the declared prefix:
<%# Register TagPrefix="uc1" TagName="Pcp" Src="../../Controls/ClientPayement.ascx" %>
And use the control as you posted in the question:
<uc1:Pcp ID = "pcpClient1"></uc1:Pcp>
EDIT
As Shai Cohen pointed out in another answer, you are also missing the runat="server" from the usercontrol tag.
<uc1:Pcp ID = "pcpClient1" runat="server"></uc1:Pcp>
In addition to Juan's answer, you are also missing runat="server".
I am doing this:
<% Html.RenderPartial("SomePartial", Model); %>
My Model has a property UserID
In my partial I try this:
<%= Model.UserID %>
but I get this error:
CS1061: 'object' does not contain a definition for 'UserID' and no extension method 'UserID' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Blankman,
Make sure your partial ascx file defines the model as per the main view i.e:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Your.Model>" %>
[edit] - as Stefanvds mentions below, if you only need the id portion from the model, then define your partial as:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int>" %>
that would be the definitive i reckon :)
cheers
Make sure that at the top of your partial view you have Inherits attribute of your Control tag set to the type of the model you're passing in:
Inherits="System.Web.Mvc.ViewUserControl<MyNamespace.MyStronglyTypedModel>"
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DB.Models.TheModelYouWantToSend>" %>
your partial should start with this.
also, if you want to send the whole model, you dont need to specify it.
<% Html.RenderPartial("SomePartial"); %>
or if you would only like to send the ID.
<% Html.RenderPartial("SomePartial", Model.UserID); %>
which would make the header
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int>" %>
The model type on your Partial View and the model you pass in to Html.RenderPartial method should match.
Asp.net: Can we use MasterPage's viewstate in ContentPage ?
From a Content Page you can refer to a MasterPage through the Master Property. Create a Property on the Master Page that uses its getter and setter to store its value in ViewState, like so:
string MyProperty
{
get { return ViewState["MyProperty"] as string; }
set { ViewState["MyProperty"] = value; }
}
Obviously you could make that code safer by testing for nulls and what-not...
Here's the important bit: Viewstate elements are only accessible from the controls that added them so you need to refer back up the tree.
You can also strongly type the Master property on Page by using the <%# MasterType %> directive in your ASPX file, thusly:
<%# MasterType VirtualPath="~/masters/SourcePage.master"" %>
HTH.