Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikolas van Etten 202 posts 162 karma points
    Mar 16, 2010 @ 16:33
    Nikolas van Etten
    0

    Dictionary items in asp:buttons

    I need to set the value of a search button and thought about using a dictionary item, but as the button is defined with the following code, I don't know how to place it:

    <asp:button ID="TopSearchButton" runat="server" text="Search" CssClass="submit" onClick="TopSearchButton_Click"></asp:button>

    The button is declared directly in the template (no user control or similar).

    Also the search should redirect to different sites, so any way to insert a dictionary item in server side code (also in template?

    protected void TopSearchButton_Click(object sender, EventArgs e)
    { 
        Response.Redirect("/en/search.aspx?search=" + TopSearchText.Text);
    }

    So basically I want to insert a dictionary item in the text value of the button as well as in the redirect address value.

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Mar 16, 2010 @ 16:53
    Matt Brailsford
    0

    You could always defind a script block at the top of your template with the runat="server" attribute set and create a Page_Load method to set the text?

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            TopSearchButton.Text = ...
    TopSearchButton.PostBackUrl = ...

        }
    </script>
  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Mar 16, 2010 @ 16:56
    Matt Brailsford
    0

    An alternative to postbackurl could also be to use a command instead of a click handler, and just programitically set the commandargument to be the value you want to pass on the querystring?

  • dandrayne 1138 posts 2262 karma points
    Mar 16, 2010 @ 17:26
    dandrayne
    0

    Seems like using a hammer to crack a nut, unless there is other functionality not mentioned above?  A simple

    <form action="/en/search.aspx" method="get">
    <input type="text" name="search" />
    <input type='submit' value='<umbraco:Item runat="server" name="#dict"></umbraco:Item>' />
    </form>

    might work here?

    Dan

     

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Mar 17, 2010 @ 09:50
    Matt Brailsford
    0

    Fair point,

    I had assumed he was using asp.net controls for a reason, but at least he has a couple of options now.

    Matt

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies