How to Change PostBackUrl from Client

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.
 
L

Laurent Bugnion [MVP]

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
 
G

Guest

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
 
L

Laurent Bugnion [MVP]

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
 
Joined
May 13, 2011
Messages
1
Reaction score
0
He needed a server side solution...

Laurent Bugnion [MVP];1995332 said:
Hi,

Rajiv Das wrote:
> 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...

Understand that there's a chance Javascript may not be enabled on the users browser.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top