PostBackUrl with a variable attached?

K

KBuser

I've been looking around for the proper syntax, and have only found one
instance where it appeared somebody else was trying the same thing, but
didn't post how they had achieved their desired result.

What I want to do is PostBackUrl="mypage.asp?myid="+txtSearch

where txtSearch is the name of my text box containing the variable i
want to pass.... I assume I need {0} or something of the sort, and have
tried many different syntax variations, but cannot seem to get this to
work properly.
 
A

Anthony Merante

For this situation you have 2 options.

String.Format()
String.Concat()

I would use concat in this instance.

string.Concat("mypage.asp?id=", textSearch)

Here is the Format()
string.Format("mypage.aspx?id={0}", txtSearch)

HTH,
Tony
 
K

KBuser

Anthony said:
For this situation you have 2 options.

String.Format()
String.Concat()

I would use concat in this instance.

string.Concat("mypage.asp?id=", textSearch)

Here is the Format()
string.Format("mypage.aspx?id={0}", txtSearch)

HTH,
Tony


Thank you Anthony, but I'm not sure if that is what I'm looking for...
I have my button, btnSearch, and I want to put a variable into one of
its attributes, without having to do any c# or vb coding.
<asp:Button ID="btnSearch" runat="server" Text="Search"
PostBackUrl="dvd.aspx?dvd={0}",txtSearch />

This is my first ASP.NET project (I'm using visual web dev 2005), so I
apologize if I'm misunderstanding what you're saying to do....
 
P

Paul Henderson

I have my button, btnSearch, and I want to put a variable into one of
its attributes, without having to do any c# or vb coding.
<asp:Button ID="btnSearch" runat="server" Text="Search"
PostBackUrl="dvd.aspx?dvd={0}",txtSearch />

If you have the variable txtSearch initialised *before* the page is
rendered (i.e. it is determined beforehand on the server side) then
there is no way of doing exactly what you want; just add some code to
your OnLoad event to set the required property.

If not, use Javascript or do a postback first...I doubt this is what
you want, though
 
P

Paul Henderson

... then there is no way of doing exactly what you
want; just add some code to
your OnLoad event to set the required property.

You could actually try <asp:Button ID="whatever" runat="server"
Text="search" PostBackUrl="dvd.aspx<%txtSearch%>">, which will cause
the parser to evaluate the expression inside the <% %> tags and insert
it.
 
P

Paul Henderson

PostBackUrl="dvd.aspx<%txtSearch%>">

Hehe, bad typing day today. There should be an equals sign after the
first %
 
K

KBuser

Paul said:
Hehe, bad typing day today. There should be an equals sign after the
first %

Thanks, I think this is close to what I want. The text box i'm reading
from is on the same page as the button, and the only reason why I don't
use the text box as the datasource for my gridview is because I need to
load this page from other pages as well (which pass a dvd id to search
for).
PostBackUrl="dvd.aspx<%=txtSearch%>">
Produces
dvd.aspx%3C%=txtSearch%%3E
at the end of my querystring, and gives an error:
The connection was reset
The connection to the server was reset while the page was loading.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top