How to display parameter passed to a page in a textbox control

Discussion in 'ASP .Net Web Controls' started by Morris Neuman, Apr 9, 2007.

  1. Hi,

    I have a gridview control on a page that has as its column a hyperlink
    field. This hyperlink field opens another page and passes a parameter.
    The hyperlink field has values as follows:
    DataNavigateUrlFormatString = ManageUser-MBoxes.aspx?User={0}
    DataNavigateUrlsFields = UserName.
    The gridview is bound to an SqlDataSource control which returns the value of
    UserName.

    I want to display the value of the selected UserName field passed in the
    parameterwhen the linked page is open in a TextBox control.

    How do I bind the value of the TextBox control the the parameter passed to
    the page via the hyperlink?

    Any help would be appreciated.
    --
    Thanks
    Morris
    Morris Neuman, Apr 9, 2007
    #1
    1. Advertising

  2. Hi Morris,

    As for the "bind url parameter from linked page to textbox" issue, I think
    you can consider the following means:

    1. If using code behind is acceptable, you can simply put the following
    code in Page_load event to attach the querystring parameter to the Textbox.
    e.g.

    ===============
    protected void Page_Load(object sender, EventArgs e)
    {
    txtUsername.Text = Request.QueryString["User"];
    }
    ===============

    2. Another approach is using databinding expression, e.g.

    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txtUsername" runat="server" Text='<%#
    Request.QueryString["User"] %>'></asp:TextBox>

    but you need to explicitly call "DataBind" method of the textbox to trigger
    the databinding:

    protected void Page_Load(object sender, EventArgs e)
    {
    ............
    txtUsername.DataBind();

    }



    3. Another means is use the new feature of ASP.NET 2.0, you can build a
    custom expression builder. This can help you embed normal codesnippet in
    your ASP.NET server control's tag(attribute). Here is a good blog article
    detailedly describe this:

    #The CodeExpressionBuilder
    http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionB
    uilder.aspx

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Apr 9, 2007
    #2
    1. Advertising

  3. Hi Steven,

    I used option 2 and it worked well. Thanks for your help.
    --
    Regards,
    Morris


    "Steven Cheng[MSFT]" wrote:

    > Hi Morris,
    >
    > As for the "bind url parameter from linked page to textbox" issue, I think
    > you can consider the following means:
    >
    > 1. If using code behind is acceptable, you can simply put the following
    > code in Page_load event to attach the querystring parameter to the Textbox.
    > e.g.
    >
    > ===============
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > txtUsername.Text = Request.QueryString["User"];
    > }
    > ===============
    >
    > 2. Another approach is using databinding expression, e.g.
    >
    > <form id="form1" runat="server">
    > <div>
    > <asp:TextBox ID="txtUsername" runat="server" Text='<%#
    > Request.QueryString["User"] %>'></asp:TextBox>
    >
    > but you need to explicitly call "DataBind" method of the textbox to trigger
    > the databinding:
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > ............
    > txtUsername.DataBind();
    >
    > }
    >
    >
    >
    > 3. Another means is use the new feature of ASP.NET 2.0, you can build a
    > custom expression builder. This can help you embed normal codesnippet in
    > your ASP.NET server control's tag(attribute). Here is a good blog article
    > detailedly describe this:
    >
    > #The CodeExpressionBuilder
    > http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionB
    > uilder.aspx
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    >
    >
    >
    Morris Neuman, Apr 10, 2007
    #3
    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. S. Justin Gengo
    Replies:
    0
    Views:
    495
    S. Justin Gengo
    Jul 16, 2003
  2. dee
    Replies:
    9
    Views:
    495
    Joseph Byrns
    Apr 15, 2005
  3. ABC
    Replies:
    2
    Views:
    757
    Praveen
    Oct 4, 2005
  4. Anand
    Replies:
    2
    Views:
    890
    Anand
    Sep 11, 2003
  5. soren625
    Replies:
    10
    Views:
    230
    Kevin Collins
    Dec 28, 2005
Loading...

Share This Page