How to Change PostBackUrl from Client

Discussion in 'ASP .Net' started by Guest, Feb 21, 2007.

  1. Guest

    Guest Guest

    I want to postback to the Search.aspx from default.aspx.

    I have a textbox and a button on default.aspx

    I want the postbackurl to be Search.aspx?q={textbox.text}

    How to achieve this?

    Any hacks?

    I am currently doing a self-post back + redirect.
    Guest, Feb 21, 2007
    1. Advertisements

  2. Hi,

    You can access the ACTION attribute of the form using JavaScript.

    <form id="myForm" action="Search.aspx" onsubmit="return setAction();">
    <input id="textbox" />
    <input type="submit" value="Submit" />

    <script type="text/javascript">

    function setAction()
    var myForm = document.getElementById( "myForm" );
    var myText = document.getElementById( "textbox" );

    if ( myForm
    && myForm.action
    && myText
    && myText.value != null )
    myForm.action = "Search.aspx?q=" + myText.value;
    return true;


    Laurent Bugnion [MVP], Feb 21, 2007
    1. Advertisements

  3. Guest

    Guest Guest

    That should work, but doesn't smell like 2.0 [:)]

    nonethe less, thanks.another hack I found

    Button1.PostBackUrl = "javascript:SayHello()";
    function SayHello()
    location.href = "default2.aspx?q=" +

    Rajiv Das

    Guest, Feb 21, 2007
  4. Hi,

    JavaScript works on ASP.NET 2.0 just like I works on normal HTML. I
    don't quite understand the comment...
    That's not a POST, it's a GET. Additionally, you don't want to use the
    javascript: pseudo protocol, it's known to cause problems. Don't want to
    tell you what this smells like...

    Laurent Bugnion [MVP], Feb 21, 2007
  5. Guest


    May 13, 2011
    Likes Received:
    He needed a server side solution...

    Understand that there's a chance Javascript may not be enabled on the users browser.
    theojohn, May 13, 2011
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.