More master page woes!

W

William Buchanan

Hi folks

I have a "Search" text box and LinkButton in my master page. When this is
submitted, I do a Server.Transfer to a page which contains a gridview. The
gridview is filtered on a hidden field which I set in the page load method
(from the search text box text).

Now, the grid view appears to filter correctly, however, when I select a
record in the gridview to populate a DetailsView, I loose the original
filter and so the returned page just contains an un-filtered grid view. When
I put a breakpoint on page load I can see that the search text box is
cleared and doesn't seem to keep it's value between this call and the last
one. I have got ViewState turned on.

Any ideas how I can get around this? I guess it is something to do with the
Server.Transfer, but I need to do this to get me onto the right page (since
the text box doesn't have a postbackurl - (or is it the link button)).

Thanks

Will
 
G

Guest

in your page load event are you checking for a "postback"..

e.g.

if not ispostback=true then
txtHiddenField.text="xyz"
end if
 
W

William Buchanan

Thanks for the really quick reply!!!

Here's my page load event..... gvAdList is the gridview and hfSearch is the
hidden field. The grid view is fed from an objectdatasource - I have added
it's code at the bottom:

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;
}


<asp:ObjectDataSource ID="odsAdList" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="directory.data.DS_DirectoryTableAdapters.vwAdvertListTableAdapter"
FilterExpression="CompanyName like '%{0}%' or Descr like '%{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="hfSearch" Name="CompanyName"
PropertyName="Value"
Size="150" Type="String" />
</FilterParameters>
</asp:ObjectDataSource>
 
G

Guest

try this...

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];

if not ispostback=true then 'Change this to whatever the C# syntax is..
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;

end if
}


William Buchanan said:
Thanks for the really quick reply!!!

Here's my page load event..... gvAdList is the gridview and hfSearch is the
hidden field. The grid view is fed from an objectdatasource - I have added
it's code at the bottom:

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;
}


<asp:ObjectDataSource ID="odsAdList" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="directory.data.DS_DirectoryTableAdapters.vwAdvertListTableAdapter"
FilterExpression="CompanyName like '%{0}%' or Descr like '%{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="hfSearch" Name="CompanyName"
PropertyName="Value"
Size="150" Type="String" />
</FilterParameters>
</asp:ObjectDataSource>

NH said:
in your page load event are you checking for a "postback"..

e.g.

if not ispostback=true then
txtHiddenField.text="xyz"
end if
 
W

William Buchanan

Hi

Thanks again.

I have tried this... the problem is, what happens when it is a postback?
Since the search box is on all pages (including the gridview page) I need to
catch postbacks as well.

Adding this code has however fixed the problem of the search text box
loosing it's value.

How can I get around this?


NH said:
try this...

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];

if not ispostback=true then 'Change this to whatever the C# syntax is..
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;

end if
}


William Buchanan said:
Thanks for the really quick reply!!!

Here's my page load event..... gvAdList is the gridview and hfSearch is
the
hidden field. The grid view is fed from an objectdatasource - I have
added
it's code at the bottom:

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;
}


<asp:ObjectDataSource ID="odsAdList" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="directory.data.DS_DirectoryTableAdapters.vwAdvertListTableAdapter"
FilterExpression="CompanyName like '%{0}%' or Descr like '%{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="hfSearch" Name="CompanyName"
PropertyName="Value"
Size="150" Type="String" />
</FilterParameters>
</asp:ObjectDataSource>

NH said:
in your page load event are you checking for a "postback"..

e.g.

if not ispostback=true then
txtHiddenField.text="xyz"
end if

:

Hi folks

I have a "Search" text box and LinkButton in my master page. When this
is
submitted, I do a Server.Transfer to a page which contains a gridview.
The
gridview is filtered on a hidden field which I set in the page load
method
(from the search text box text).

Now, the grid view appears to filter correctly, however, when I select
a
record in the gridview to populate a DetailsView, I loose the original
filter and so the returned page just contains an un-filtered grid
view.
When
I put a breakpoint on page load I can see that the search text box is
cleared and doesn't seem to keep it's value between this call and the
last
one. I have got ViewState turned on.

Any ideas how I can get around this? I guess it is something to do
with
the
Server.Transfer, but I need to do this to get me onto the right page
(since
the text box doesn't have a postbackurl - (or is it the link button)).

Thanks

Will
 
G

Guest

try moving the "if not ispostback=true then 'Change this to whatever the C#
syntax is.." to just above the line " if (frm != null)"

William Buchanan said:
Hi

Thanks again.

I have tried this... the problem is, what happens when it is a postback?
Since the search box is on all pages (including the gridview page) I need to
catch postbacks as well.

Adding this code has however fixed the problem of the search text box
loosing it's value.

How can I get around this?


NH said:
try this...

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];

if not ispostback=true then 'Change this to whatever the C# syntax is..
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;

end if
}


William Buchanan said:
Thanks for the really quick reply!!!

Here's my page load event..... gvAdList is the gridview and hfSearch is
the
hidden field. The grid view is fed from an objectdatasource - I have
added
it's code at the bottom:

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;
}


<asp:ObjectDataSource ID="odsAdList" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="directory.data.DS_DirectoryTableAdapters.vwAdvertListTableAdapter"
FilterExpression="CompanyName like '%{0}%' or Descr like '%{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="hfSearch" Name="CompanyName"
PropertyName="Value"
Size="150" Type="String" />
</FilterParameters>
</asp:ObjectDataSource>

in your page load event are you checking for a "postback"..

e.g.

if not ispostback=true then
txtHiddenField.text="xyz"
end if

:

Hi folks

I have a "Search" text box and LinkButton in my master page. When this
is
submitted, I do a Server.Transfer to a page which contains a gridview.
The
gridview is filtered on a hidden field which I set in the page load
method
(from the search text box text).

Now, the grid view appears to filter correctly, however, when I select
a
record in the gridview to populate a DetailsView, I loose the original
filter and so the returned page just contains an un-filtered grid
view.
When
I put a breakpoint on page load I can see that the search text box is
cleared and doesn't seem to keep it's value between this call and the
last
one. I have got ViewState turned on.

Any ideas how I can get around this? I guess it is something to do
with
the
Server.Transfer, but I need to do this to get me onto the right page
(since
the text box doesn't have a postbackurl - (or is it the link button)).

Thanks

Will
 
W

William Buchanan

Hi

Thanks again.

I did try it, but it didn't work. The thing is there is nothing in that code
which clears the text box, or the value, so the mystery seems to be that
this is being lost somewhere.

Will


NH said:
try moving the "if not ispostback=true then 'Change this to whatever the
C#
syntax is.." to just above the line " if (frm != null)"

William Buchanan said:
Hi

Thanks again.

I have tried this... the problem is, what happens when it is a postback?
Since the search box is on all pages (including the gridview page) I need
to
catch postbacks as well.

Adding this code has however fixed the problem of the search text box
loosing it's value.

How can I get around this?


NH said:
try this...

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];

if not ispostback=true then 'Change this to whatever the C# syntax is..
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;

end if
}


:

Thanks for the really quick reply!!!

Here's my page load event..... gvAdList is the gridview and hfSearch
is
the
hidden field. The grid view is fed from an objectdatasource - I have
added
it's code at the bottom:

protected void Page_Load(object sender, EventArgs e)
{
gvAdList.PageSize = (int)Session["GridPageSize"];
TextBox tb = null;
HtmlForm frm = null;
string sQry = "";

if (PreviousPage != null)
frm = PreviousPage.Form;
else if (Master != null)
frm = Form;

if (frm != null)
try
{
tb = (TextBox)frm.FindControl("tbMainSearch");
if (tb != null)
sQry = tb.Text;
}
catch { }

hfSearch.Value = sQry;
}


<asp:ObjectDataSource ID="odsAdList" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="directory.data.DS_DirectoryTableAdapters.vwAdvertListTableAdapter"
FilterExpression="CompanyName like '%{0}%' or Descr like '%{0}%'">
<FilterParameters>
<asp:ControlParameter ControlID="hfSearch"
Name="CompanyName"
PropertyName="Value"
Size="150" Type="String" />
</FilterParameters>
</asp:ObjectDataSource>

in your page load event are you checking for a "postback"..

e.g.

if not ispostback=true then
txtHiddenField.text="xyz"
end if

:

Hi folks

I have a "Search" text box and LinkButton in my master page. When
this
is
submitted, I do a Server.Transfer to a page which contains a
gridview.
The
gridview is filtered on a hidden field which I set in the page load
method
(from the search text box text).

Now, the grid view appears to filter correctly, however, when I
select
a
record in the gridview to populate a DetailsView, I loose the
original
filter and so the returned page just contains an un-filtered grid
view.
When
I put a breakpoint on page load I can see that the search text box
is
cleared and doesn't seem to keep it's value between this call and
the
last
one. I have got ViewState turned on.

Any ideas how I can get around this? I guess it is something to do
with
the
Server.Transfer, but I need to do this to get me onto the right
page
(since
the text box doesn't have a postbackurl - (or is it the link
button)).

Thanks

Will
 
S

Sol

How are you storing the text in a hidden field? Are you sure that this field
is getting re-created on the page that you are Server.Transfer'ring to?
 
W

William Buchanan

Hi Sol

The hidden field was dragged onto the page from the toolbox. I populate it
in the page load method:
hfSearch.Value = sQry; // sQry is the contents of the text box

When debugging I can see the hidden field being populated correctly.... the
issues seems to be that the text box looses it's value.

Thanks

Will
 

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,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top