Why does postbackurl and master pages work like this?

N

needin4mation

I have a search box on my master page. The results are on a child
page. To do this I changed the postbackurl to the childpage and on the
childpage I have an asp:controlparameter matching the name of the
control on the master page.

The first time I press the button on the master page it goes to the
child page, but no results are displayed in my gridview. The second
time I press my button (which is still the master page button no other
buttons) the query works and the grid is populated.

Why does it act like this? Why do I have to hit it twice?

Thanks for any help.
 
G

Guest

Any code samples? In general you shouldn't have to change the postbackurl
since the content page is the actual page being rendered, the master page is
added to it. The only thing you should have to do, is make the value on the
master page visible to the content page.
 
N

needin4mation

How do I make the "make the value on the master page visible to the
content page."?
 
C

Chris Fulstow

Perhaps you could do a page redirect in your search button's click
handler that passes the keyword to your search page, e.g.

protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("Search.aspx?keywords=" +
HttpUtility.HtmlEncode(txtKeyword.Text);
}

You could then get the keywords from Request.QueryString and build you
results in the GridView?

HTH,

Chris
 
N

needin4mation

No way to do with all drag and drop?

My button and textbox are on the master page. My results gridview is
on the child page.

so on the child page I have:

<SelectParameters>
<asp:ControlParameter ControlID="txtFreeSearch"
Name="keywordlist" Type="String"

PropertyName="Text" />

</SelectParameters>
</asp:SqlDataSource>

and on the masterpage I have

<asp:Button ID="Button1" runat="server" Text="GO!"
PostBackUrl="~/FreeSearch.aspx" /></td>

I press the button and the FreeSearch.aspx page is called. It just
doesn't populate the gridview, but the page loads. The second time
(with the FreeSearch.aspx already loaded) I hit the button, it works.
This tells me the first time I hit the button on the master page (where
default.aspx is the content page at that time), and it posts to the
child, the data is not being passed or the SelectParameters cannot see
it for some reason.
 
E

Erik Funkenbusch

Why does it act like this? Why do I have to hit it twice?

My guess is that you're doing something differently in postback than you
are when not in postback. The first time you click, you're not in postback
when you click it. The second time you click, you're page has been built
with a postback event.

As someone else mentioned, you don't need to set the postbackurl because
it's already the same page. Do you have any special postback processing?
 
G

Guest

On the content page try:
<%@ MasterType VirtualPath="Site.master" %>

Any public items on the master page you can see from the content page.
 

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

Top