ASP.NET 2.0 b2 Coontrol Parameter question

Z

Zac Maclean

We are working on a calendar event list in ASP.NET 2.0 using VWDE.

On load we create a calendar control, and a pair of nested DataLists.

the outer DataList fills from a name list from SQL 2000 query. The inner
list takes the name from each item in the outer list, and creates a task
list for each person. On initial load, the task lists are empty. We want to
do is set a default value <%# DateTime.Now %> for one of the parameters in
the second query that fills the task list.

Code Line:
<asp:ControlParameter ControlID="Calendar1" Name="DUEDATE"
PropertyName="SelectedDate" Type="DateTime" DefaultValue='<%# DateTime.Now
%>' />

does not work. Neither does trying to assign a value in the code black, as
the control has not been created yet. We have also tried inserting a code
block inside the document just behind the control creation, but it does not
work.


If we need to change to a "code behind" page style that is ok, but I'd
rather try to keep in the overall .NET 2.0 framework defaults.


TIA

Z
 
B

Brock Allen

You'll need to add a Page_Load and access the Parameters in code to set the
DefaultValue.

The other option is to use an ExpressionBuilder. You ASPX will look like
this:

<asp:ControlParameter ControlID="Calendar1" Name="DUEDATE"
PropertyName="SelectedDate" Type="DateTime"
DefaultValue='<%$ DateTimeNow:d %>' />

This is using an expression builder. It's syntax to execute code to do the
default assignment of that value when the ASP.NET parser creates the page
code from the ASPX. But this will require an expression builder class. You
can add a new .cs file to your App_Code folder that looks like this:

using System;
using System.Web.Compilation;
using System.Web.UI;
using System.CodeDom;

public class DateTimeNow : ExpressionBuilder
{
public static string GetNow(string param)
{
return DateTime.Now.ToString(param);
}
public override System.CodeDom.CodeExpression GetCodeExpression(BoundPropertyEntry
entry, object parsedData, ExpressionBuilderContext context)
{
CodeMethodInvokeExpression ex = new CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(typeof(DateTimeNow)), "GetNow", new CodePrimitiveExpression(entry.Expression.ToString().Trim()));
return ex;
}
}

And then in web.config you'll need a new entry:

<compilation debug="true" defaultLanguage="C#">
<expressionBuilders>
<add expressionPrefix="DateTimeNow" type="DateTimeNow, __code" />
</expressionBuilders>
</compilation>
 
Z

Zac Maclean

Wow.. that worked cut/paste. Where do I send the check? j/k.

We found another issue w/ date info passing, but working off this snippet, I
think we can get it going.

Thanks alot, for both code, and fast response!

Z
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top