|
-
Sep 27th, 2010, 08:56 AM
#1
[RESOLVED] Checkbox - Postback ?
Hi All,
firstly i am not really an ASP.Net developer but i do work in C#.
Anyway one of the application that i develop has an ASP.Net section and i need to amend it.
I want to add a Checkbox which when Checked by the User will set a Session variable.
This Session variable will then be accessed on another page where it will include/disclude some SQL and therefore change the behaviour of a Search.
So i have 2 Pages - Page1 that has the Checkbox on it -
HTML
<asp:CheckBox ID="ChkShowOldVer" runat="server" AutoPostBack="true"
oncheckedchanged="ChkShowOldVer_CheckedChanged" Text="Show Old Versions" />
</a>
The Event Handler
protected void ChkShowOldVer_CheckedChanged(object sender, EventArgs e)
{
Session["ShowOldVersions"] = ChkShowOldVer.Checked.ToString();
}
And Page 2 which builds the Search criteria and displays the results in a separate Frame (not how i would have done it i hate Frames, but i dont have the option of changing it)
And what i want to do is
ShowOldVer = HttpContext.Current.Session["ShowOldVersions"].ToString();
if (ShowOldVer == "True")
{
//Build Extra SQL here !
}
Now i have 2 main problems.
1, How do i stop the whole page from executing again when doing a postback ? I only want the Changed Event to run not the whole page !
2, Why does the Checkbox not appear to Change the Checked value after postback ?
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
Sep 27th, 2010, 09:39 AM
#2
Re: Checkbox - Postback ?
, How do i stop the whole page from executing again when doing a postback ? I only want the Changed Event to run not the whole page !
May be you could go for Ajax..
Please mark you thread resolved using the Thread Tools as shown
-
Sep 27th, 2010, 09:49 AM
#3
Re: Checkbox - Postback ?
Hey,
Since you have AutoPostBack set to True, everytime you check the CheckBox, it should immediately PostBack to the server. Is this not happening?
In the Page Load event, you can use the Page.IsPostBack property to segregate the work done when the page is loaded for the first time, and when it subsequently gets posted back.
I am a little confused by the second portion of your question. What exactly do you mean?
Gary
-
Sep 27th, 2010, 09:50 AM
#4
Re: Checkbox - Postback ?
 Originally Posted by danasegarane
May be you could go for Ajax..
I thought this is what the OP was referring to as well, but wasn't sure.
If they are not already using AJAX, then it might be a bit of a stretch to implement this.
Gary
-
Sep 27th, 2010, 10:10 AM
#5
Re: Checkbox - Postback ?
Since you have AutoPostBack set to True, everytime you check the CheckBox, it should immediately PostBack to the server. Is this not happening?
In the Page Load event, you can use the Page.IsPostBack property to segregate the work done when the page is loaded for the first time, and when it subsequently gets posted back.
Yes & Yes both are happeinnig, Right i will try and fully clarify as i have looked into it a bit further now.
The application actually has 3 pages (the application uses frames unfortunately) they all get posted back to yet only the first page knows it !!! The other two still have IsPostback set to false, and yet they get reloaded as well.
(The format is basically 1 frame the full width of the page along the top with the Search bar on it and 2 further frames below this one on the left which holds a tree view control and a results pain on the right.)
When i tick the Checkbox it does not do anything on the display, i.e. No Tick !! do i have to do something in code to set it ?
Also i have noticed that my event handler is not running during the postback
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
Sep 27th, 2010, 10:17 AM
#6
Re: Checkbox - Postback ?
I would suggest to implement the PreviousPage.Findcontrol method.
Refer : How to: Pass Values Between ASP.NET Web Pages
Please mark you thread resolved using the Thread Tools as shown
-
Sep 27th, 2010, 02:41 PM
#7
Re: Checkbox - Postback ?
Hey,
Although Dana's suggestion has it's place, I would hesitate about closely coupling pages like that, unless you really need to.
NeedSomeAnswers, is it possible that you can knock up a small sample application, that has the main points of the full application? i.e. the 3 pages, the frame, and the checkbox, ensure that it is doing what you are seeing, and then post the project here?
I think that would be the easiest way to try and help you.
Gary
-
Sep 28th, 2010, 03:33 AM
#8
Re: Checkbox - Postback ?
Thanks Dana / Gary,
Dana - i have looked into that but i dont think it will give me what i want because of the 3 frames.
Gary, i have a couple of thing i want to try first, but if i dont get anywhere, then i will be making a test application and i will upload.
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
Sep 28th, 2010, 03:45 AM
#9
Re: Checkbox - Postback ?
Does the 3 frames uses asp.net controls ?
Did you try to use the PreviousPage.FindControl("ControlName") Method ?
Please mark you thread resolved using the Thread Tools as shown
-
Sep 28th, 2010, 07:06 AM
#10
Re: Checkbox - Postback ?
 Originally Posted by NeedSomeAnswers
Gary, i have a couple of thing i want to try first, but if i dont get anywhere, then i will be making a test application and i will upload.
Sounds like a plan!
Gary
-
Sep 28th, 2010, 10:58 AM
#11
Re: Checkbox - Postback ?
Does the 3 frames uses asp.net controls ?
They use a mix of ASP.Net and HTML controls
Did you try to use the PreviousPage.FindControl("ControlName") Method
I did try but i couldn't get it work within the frameset
What i found was this -
When you have Frames postback isn't very useful at least in this application. I initially added the ASP.Net checkbox control to the top frame, but when you ticked it and it did a postback it didn't postback to the same frame first but to one of the frames. The other frame then had Postback set to FALSE as it didn't even know that it was a postback, and it would re-load each frame in turn.
Because of this i kept going in circles, i didn't want all the frames to be posted back when the user checked the checkbox, so in the end i have opted for a HTML checkbox.
Now i have the HTML Checkbox which runs a JavaScript function, this function based on whether there is any search criteria, runs the Search Function (which already exists)
The Search Function just uses a query string to reload the main listing page like this;
vb Code:
parent.frames('ListFrame').location.href='List.aspx?' + ( SearchDesc ? 'D' : 'F' ) + '=' + t2 + CheckValue;
and i have just tagged along an extra value on to the query.
In the List page i can then take the extra query value and use that to change the search criteria.
So in the end it was reasonably simple as long as i used JavaScript instead of ASP.Net.
To be honest it was mainly the frames fault, i really do not like Frames, they are a pain in the arse !
Anyway thanks to you both, but this is now resolved !
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
Sep 28th, 2010, 12:04 PM
#12
Re: [RESOLVED] Checkbox - Postback ?
Hey,
Glad to hear that you got this working.
Now that you have explained everything, it seems that the solution that you have arrived at is probably the best one, apart from obviously factoring out the frames entirely.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|