How to Change PostBackUrl from Client

  • Thread starter Thread starter Guest
  • Start date Start date
G

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.
 
Hi,

Rajiv said:
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.

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" />
</form>

<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;
}

</script>

HTH,
Laurent
 
That should work, but doesn't smell like asp.net 2.0 [:)]


nonethe less, thanks.another hack I found

Button1.PostBackUrl = "javascript:SayHello()";
function SayHello()
{
location.href = "default2.aspx?q=" +
document.getElementById("TextBox1").value;
}


--
---------------------
Thanks
Rajiv Das


Laurent Bugnion said:
Hi,

Rajiv said:
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.

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" />
</form>

<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;
}

</script>

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Hi,

Rajiv said:
That should work, but doesn't smell like asp.net 2.0 [:)]

JavaScript works on ASP.NET 2.0 just like I works on normal HTML. I
don't quite understand the comment...
nonethe less, thanks.another hack I found

Button1.PostBackUrl = "javascript:SayHello()";
function SayHello()
{
location.href = "default2.aspx?q=" +
document.getElementById("TextBox1").value;
}

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
 
Back
Top