passing variables from .aspx.cs code pages to .aspx pages

Discussion in 'ASP .Net Web Controls' started by RadioSignal, Sep 12, 2005.

  1. RadioSignal

    RadioSignal Guest

    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?
     
    RadioSignal, Sep 12, 2005
    #1
    1. Advertising

  2. 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=?=" <>
    | Subject: passing variables from .aspx.cs code pages to .aspx pages
    | Date: Mon, 12 Sep 2005 12:49:01 -0700
    | Lines: 5
    | Message-ID: <>
    | 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?
    |
     
    Steven Cheng[MSFT], Sep 13, 2005
    #2
    1. Advertising

  3. 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: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: (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: <>
    | 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=?=" <>
    | | Subject: passing variables from .aspx.cs code pages to .aspx pages
    | | Date: Mon, 12 Sep 2005 12:49:01 -0700
    | | Lines: 5
    | | Message-ID: <>
    | | 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?
    | |
    |
    |
     
    Steven Cheng[MSFT], Sep 16, 2005
    #3
  4. RadioSignal

    RadioSignal Guest

    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: <>
    > | MIME-Version: 1.0
    > | Content-Type: text/plain
    > | Content-Transfer-Encoding: 7bit
    > | From: (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: <>
    > | 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=?=" <>
    > | | Subject: passing variables from .aspx.cs code pages to .aspx pages
    > | | Date: Mon, 12 Sep 2005 12:49:01 -0700
    > | | Lines: 5
    > | | Message-ID: <>
    > | | 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?
    > | |
    > |
    > |
    >
    >
     
    RadioSignal, Sep 19, 2005
    #4
  5. 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=?=" <>
    | References: <>
    <>
    <>
    | 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: <>
    | 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: <>
    | > | MIME-Version: 1.0
    | > | Content-Type: text/plain
    | > | Content-Transfer-Encoding: 7bit
    | > | From: (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: <>
    | > | 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=?=" <>
    | > | | Subject: passing variables from .aspx.cs code pages to .aspx pages
    | > | | Date: Mon, 12 Sep 2005 12:49:01 -0700
    | > | | Lines: 5
    | > | | Message-ID: <>
    | > | | 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?
    | > | |
    | > |
    | > |
    | >
    | >
    |
     
    Steven Cheng[MSFT], Sep 20, 2005
    #5
  6. RadioSignal

    RadioSignal Guest

    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=?=" <>
    > | References: <>
    > <>
    > <>
    > | 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: <>
    > | 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: <>
    > | > | MIME-Version: 1.0
    > | > | Content-Type: text/plain
    > | > | Content-Transfer-Encoding: 7bit
    > | > | From: (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: <>
    > | > | 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=?=" <>
    > | > | | Subject: passing variables from .aspx.cs code pages to .aspx pages
    > | > | | Date: Mon, 12 Sep 2005 12:49:01 -0700
    > | > | | Lines: 5
    > | > | | Message-ID: <>
    > | > | | 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?
    > | > | |
    > | > |
    > | > |
    > | >
    > | >
    > |
    >
    >
     
    RadioSignal, Sep 20, 2005
    #6
  7. 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=?=" <>
    | References: <>
    <>
    <>
    <>
    <>
    | 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: <>
    | 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=?=" <>
    | > | References: <>
    | > <>
    | > <>
    | > | 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: <>
    | > | 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: <>
    | > | > | MIME-Version: 1.0
    | > | > | Content-Type: text/plain
    | > | > | Content-Transfer-Encoding: 7bit
    | > | > | From: (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: <>
    | > | > | 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=?="
    <>
    | > | > | | Subject: passing variables from .aspx.cs code pages to .aspx
    pages
    | > | > | | Date: Mon, 12 Sep 2005 12:49:01 -0700
    | > | > | | Lines: 5
    | > | > | | Message-ID: <>
    | > | > | | 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?
    | > | > | |
    | > | > |
    | > | > |
    | > | >
    | > | >
    | > |
    | >
    | >
    |
     
    Steven Cheng[MSFT], Sep 21, 2005
    #7
  8. RadioSignal

    Mirronelli Guest

    Hi Steven,

    I think RadioSignal is right. As I know you can't set the parameter's value
    in the datasource's selecting eventhandler, because these parameters mimic
    their declarative syntax. In other words you see the parameter definition,
    name, type etc. but you can't set the value which will be used in select.

    RadioSignal used a fake hidden textbox control, which value can be set at
    runtime. He then declared controlparameter which controlid was set to the
    textboxes' id.

    I saw also another way to solve it by using a subclassed parameter, which
    then used reflection to acces a member from page.
    http://blog.davidyack.com/comments/3385.aspx
    it looks nice, but I would really appreciate this to be part of aspnet

    And yes you really can change the value of a parameter before executing
    command but only if:
    a) you handle the target control's bindig events eg. formview.updating event
    in contrast to datasources events
    b) this works only for updates, deletes and inserts not for selects because
    these databound controls do not raise selecting events


    "Steven Cheng[MSFT]" wrote:

    > 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=?=" <>
    > | References: <>
    > <>
    > <>
    > <>
    > <>
    > | 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: <>
    > | 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=?=" <>
    > | > | References: <>
    > | > <>
    > | > <>
    > | > | 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: <>
    > | > | 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: <>
    > | > | > | MIME-Version: 1.0
    > | > | > | Content-Type: text/plain
    > | > | > | Content-Transfer-Encoding: 7bit
    > | > | > | From: (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: <>
    > | > | > | 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=?="
    > <>
    > | > | > | | Subject: passing variables from .aspx.cs code pages to .aspx
    > pages
    > | > | > | | Date: Mon, 12 Sep 2005 12:49:01 -0700
    > | > | > | | Lines: 5
    > | > | > | | Message-ID: <>
    > | > | > | | MIME-Version: 1.0
    > | > | > | | Content-Type: text/plain;
    > | > | > | | charset="Utf-8"
    > | > | > | | Content-Transfer-Encoding: 7bit
     
    Mirronelli, Oct 22, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doruk
    Replies:
    4
    Views:
    499
    Polux
    Nov 14, 2003
  2. Replies:
    9
    Views:
    988
  3. A. Atienza

    Passing code/data from code-behind to ASPX page

    A. Atienza, Dec 8, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    330
    Eliyahu Goldin
    Dec 8, 2004
  4. Doruk
    Replies:
    3
    Views:
    163
    Polux
    Nov 14, 2003
  5. aratienza

    Passing data/code from code-behind to aspx

    aratienza, Dec 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    118
    haile
    Dec 10, 2004
Loading...

Share This Page