Hi RadioSignal,
Yes, of course we can dynamically pass Parameter values for the defined
Parameters in the DataSource control, however, that's not through the
inline template because the template is used to define the parameters, but
not assign the values. In another word, the actual values of each
parameter is retrieved before the certain command of the datasource control
is executed from the parameter source rather than stored in the Datasource
control, that's also why we can not specify value of parameter in
DataSource. So you original means of modifying the Control's property is
the correct means.
Also, as I've mentioned in the previous message, the ASP.net 2.0's
DataSource controls has provide some pre processing events which can help
us access and modify the Parameters collection which will be passed to the
Command about to execute. For example, the SqlDataSource's
Selecting, Inserting, Updating, Deleting events will all contains the
parameters collection as the event's EventArgs so that we can access and
adjust the parameters before the command being executed. That'll be a good
place to do some dynamic customzation.
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: passing variables from .aspx.cs code pages to .aspx pages
| thread-index: AcW+F1Kka5cyIgYgTGKSyvBi3pIxwg==
| X-WBNR-Posting-Host: 192.85.47.2
| From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: RE: passing variables from .aspx.cs code pages to .aspx pages
| Date: Tue, 20 Sep 2005 12:13:03 -0700
| Lines: 251
| Message-ID: <
[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10934
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thank you. I would think passing a parameter from C# code behind to the
| DataSource would be a fairly common application requirement. For example,
| when the C# code behind figures out which records to SELECT and wants to
| update the WHERE ID = @Param1 value in the SQL command. Doing this by
| modifying an invisible TextBox.Test value and specifying it as a control
| parameter for Name = "@Param1" works real well, but I thought there had
to be
| a better way...
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi RadioSignal,
| >
| > Thanks for your response. Well, from your further description and the
code
| > snippet, I've got the cause of your problem, for ASP.NET server
control, we
| > can't assign the value in their template through
| > <% %> code block.
| >
| > also, we can only assign top level property value for ASP.NET controls
| > through <%# ... %> or <%$ ...%> expressions. And for the
| > <XXXParameters> in the XXDataSource control, I'm afraid they can only
be
| > delared on page statically, we can't use code expression to add them
| > dynamically since they're required to be fixed and determined at
compiled
| > time much ealier before our code in <% ... %> get executed. Is there
any
| > particular requirement in your application that you need to dynamically
| > define paramters for datasrouce control?
| >
| > Based on my experience, we should always define the parameters
statically
| > in the aspx page's inline template , but we can adjust those
parameters'
| > value at runtime through DataSource control's certain events.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure!
www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | Thread-Topic: passing variables from .aspx.cs code pages to .aspx
pages
| > | thread-index: AcW9K+6+QUV3lzniREapxuaXQZ8s8g==
| > | X-WBNR-Posting-Host: 192.85.47.2
| > | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <
[email protected]>
| > | References: <
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > | Subject: RE: passing variables from .aspx.cs code pages to .aspx pages
| > | Date: Mon, 19 Sep 2005 08:08:03 -0700
| > | Lines: 166
| > | Message-ID: <
[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:10900
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > |
| > | Steven, Thank you for the help, but I am still having problems with
these
| > | parameters. Here is my aspx.cs:
| > |
| > | public partial class Test : System.Web.UI.Page
| > | {
| > | protected string MyPatientID;
| > |
| > | protected void Page_Load(object sender, EventArgs e)
| > | {
| > | //What I'd like to do:
| > | MyPatientID = "13";
| > |
| > | //What I have to do:
| > | TextBox1.Text = "13";
| > | }
| > | }
| > |
| > | However, in aspx:
| > |
| > | <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$
| > | ConnectionStrings:MyConnectionString %>"
| > |
| > | SelectCommand="SELECT PatientID, BarCode, ChartID, EmpID,
| > | NameID, Diagnosis, BeginTime FROM Patients WHERE (PatientID =
@Param1)">
| > |
| > | <SelectParameters>
| > |
| > | What I want to do:
| > |
| > | <%Param1 = MyPatientID;%>
| > |
| > | What I have to do:
| > |
| > | <asp:ControlParameter ControlID="TextBox1"
Name="Param1"
| > | PropertyName="Text" />
| > |
| > | </SelectParameters>
| > |
| > | </asp:SqlDataSource>
| > |
| > |
| > | I am receiving the error - Code block not allowed in this context.
| > |
| > | Any ideas how to get access to the MyPatientID variable in the
<Select
| > | Parameters> section?
| > |
| > | "Steven Cheng[MSFT]" wrote:
| > |
| > | > Hi RadioSignal,
| > | >
| > | > How are you doing on this issue and does the suggestions in my last
| > reply
| > | > helps a littile? If there're anything else we can help, please feel
| > free to
| > | > post here. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure!
www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | > --------------------
| > | > | X-Tomcat-ID: 60741222
| > | > | References: <
[email protected]>
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain
| > | > | Content-Transfer-Encoding: 7bit
| > | > | From: (e-mail address removed) (Steven Cheng[MSFT])
| > | > | Organization: Microsoft
| > | > | Date: Tue, 13 Sep 2005 02:00:47 GMT
| > | > | Subject: RE: passing variables from .aspx.cs code pages to .aspx
pages
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | > | Message-ID: <
[email protected]>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | > | Lines: 66
| > | > | Path: TK2MSFTNGXA01.phx.gbl
| > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.webcontrols:10807
| > | > | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
| > | > |
| > | > | Hi RadioSignal,
| > | > |
| > | > | Welcome to ASPNET newsgroup.
| > | > | Regarding on the accessing variable defined in codebehind
| > page(aspx.cs.)
| > | > | from aspx template, I think we can just make those Page member
| > variable
| > | > as
| > | > | non-private(protected or public). Because at runtime, the
dynamically
| > | > | compiled page class is a concrete class derived from the
codebehind
| > page
| > | > | class, so any protected or public page member variables can be
| > accessed
| > | > | from the dynamic compiled page. For example, we can define the
| > following
| > | > | page variable in codebehind:
| > | > |
| > | > | =============
| > | > | public partial class SimplePage : System.Web.UI.Page
| > | > | {
| > | > | protected string PageId;
| > | > |
| > | > | protected void Page_Load(object sender, EventArgs e)
| > | > | {
| > | > | PageId = "Simple Page";
| > | > | }
| > | > | ......
| > | > | ============
| > | > |
| > | > | then, in aspx , we can access the variable like:
| > | > |
| > | > | ....
| > | > | <body>
| > | > | <form id="form1" runat="server">
| > | > | <div>
| > | > | <%= PageId %>
| > | > |
| > | > | </div>
| > | > | ...
| > | > |
| > | > |
| > | > | Also, we can also define page's member function like this and
used in
| > | > aspx.
| > | > |
| > | > |
| > | > | Thanks,
| > | > |
| > | > | Steven Cheng
| > | > | Microsoft Online Support
| > | > |
| > | > | Get Secure!
www.microsoft.com/security
| > | > | (This posting is provided "AS IS", with no warranties, and
confers no
| > | > | rights.)
| > | > | --------------------
| > | > | | Thread-Topic: passing variables from .aspx.cs code pages to
.aspx
| > pages
| > | > | | thread-index: AcW30wXnzYsf2ItsR+il49U22FxHdg==
| > | > | | X-WBNR-Posting-Host: 192.85.47.2
| > | > | | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?="
<
[email protected]>
| > | > | | Subject: passing variables from .aspx.cs code pages to .aspx
pages
| > | > | | Date: Mon, 12 Sep 2005 12:49:01 -0700
| > | > | | Lines: 5
| > | > | | Message-ID: <
[email protected]>
| > | > | | MIME-Version: 1.0
| > | > | | Content-Type: text/plain;
| > | > | | charset="Utf-8"
| > | > | | Content-Transfer-Encoding: 7bit
| > | > | | X-Newsreader: Microsoft CDO for Windows 2000
| > | > | | Content-Class: urn:content-classes:message
| > | > | | Importance: normal
| > | > | | Priority: normal
| > | > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | > | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | > | | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | > | | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | > | | Xref: TK2MSFTNGXA01.phx.gbl
| > | > | microsoft.public.dotnet.framework.aspnet.webcontrols:10804
| > | > | | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.webcontrols
| > | > | |
| > | > | | I have been using dummy invisible text boxes and labels defined
in
| > the
| > | > VS
| > | > | | 2005 designer to pass parameters between my code behind pages
and
| > my
| > | > | .aspx
| > | > | | pages. This works but there's got to be a better way? How do I
give
| > my
| > | > | .aspx
| > | > | | page visibility to variables declared in my .aspx.cs code
instead
| > of
| > | > | using
| > | > | | the dummy controls that I'm using now?
| > | > | |
| > | > |
| > | > |
| > | >
| > | >
| > |
| >
| >
|