473,388 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ASP.NET 2.0 b2 Coontrol Parameter question

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
Nov 19 '05 #1
2 1369
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>

-Brock
DevelopMentor
http://staff.develop.com/ballen
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


Nov 19 '05 #2
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

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:95**********************@msnews.microsoft.com ...
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>

-Brock
DevelopMentor
http://staff.develop.com/ballen
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



Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
1
by: Prashanth | last post by:
Hi , I want to make a stored proc call thru .NET . I use the SqlParameter objects to create input parameters and set it's value. SqlParameter myParameter = new...
3
by: Aguilar, James | last post by:
Hey all. I was making a newbie mistake that I eventually figured out. That is not my question. My question is about the error message. So let me set the stage for you: class Superclass {...
3
by: thomas goodwin | last post by:
I have a query which asks for a parameter value to execute it. To see the results I have to: a) click on the query -- the "Enter Parameter Value" window pops up. b) enter the parameter value c)...
6
by: hecsan07 | last post by:
I am writing some code that passes two parameters to a store procedure. One of the parameters is an output parameter. I am querying the DB using the input value and returning a field from the...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
12
by: Darwin Lalo | last post by:
I have a lot of code like this: VOID CALLBACK TimerRoutine(PVOID lpParam) { long nTaskid = (long)lpParam; GObj *obj; if( mapThreadSafe.find( nTaskid, obj )) // mapThreadSafe is a hash_map,...
6
by: damiensawyer | last post by:
Hi, Can someone please explain to me something about delegates? My understanding is as follows. A delegate is basically an object that can hold a reference to a "method" somewhere. That is,...
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
3
by: mturner64 | last post by:
I am using Microsoft VWD 2008 express edition. I have linked an Access 2007 database to my asp.net application using a gridview control. On the webpage are four text boxes allowing a user to input...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.