a1jit Posted October 25, 2005 Posted October 25, 2005 Hi Guys, Im not sure what is wrong here, but i have totally no idea what is happening I have a form with 2 checkbox and a label and also a submit button. Basically what im trying to achieve is when user click submit button, it check if none of checkbox is selected, then display message in Label saying "Pls select at least one checkbox" if either one checkbox is selected, then process request and display in Label saying "Pls wait, request is being processed. So now the problem is that everything works fine, but the message is not getting displayed in the Label (Name of this Label is Label1) This is the html code for label ..Its in the form tag <FORM runat="server"> <TABLE cellSpacing="0" cellPadding="5" width="53%" align="center" border="0"> <TR bgcolor=#ff9900> <asp:Label ID=Label1 Runat="server"></asp:Label> </TR> </TABLE> </FORM> All the labels and checkbox and also submit button has the "runat server attribute" Then when submit button clicked, it goes to Process function and checks whether the checkbox is selected or not and displays appropriate message if (CheckBox1.Checked != true && CheckBox2.Checked != true) Label1.Text = "Please select at least One Report"; else Label1.Text = "Request is being Processed"; this code is in the <script> tag. When i try to debug no error, and it moves to the correct path, meaning it executes that statement where the label is being assigned to some value, but i dont see it in the browser.. I dont know why for some reasons the text is not being displayed in the label. Would appreciate if someone could guide me here..thank you.. Quote
Administrators PlausiblyDamp Posted October 25, 2005 Administrators Posted October 25, 2005 If it is executing one of the Label1.Text lines then it should be displaying the label correctly. If you search the HTML sent to the browser is the string present there? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
scalf Posted October 25, 2005 Posted October 25, 2005 (edited) No problem identified I had not problem identified (Maybe I didn't understand what you wanted to do, but here is the code and the label displays correctly). Are you sure that the property "CausesValidation" of your button is set to true ? VB code : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Not Me.CheckBox1.Checked And Not Me.CheckBox2.Checked Then Me.Label1.Text = "You must Click at least one checkbox !" Else Me.Label1.Text = "Pls wait, request is being processed" End If End Sub Edited October 25, 2005 by scalf Quote Scalf. Do not want others to know what you have done? Better not have done it anyways.
a1jit Posted October 26, 2005 Author Posted October 26, 2005 Hi, thx for the input.. When i check in browser the value is not sent, but when i debug, it executes one of the if condition. The browser displays <span id="Label1"></span> But when i put the if statement for this label code in Page_Load Function, it works properly.. so weird..no idea whats wrong Quote
a1jit Posted October 26, 2005 Author Posted October 26, 2005 Hi Guys, I found another weird situation.. This function executes when submit button is clicked..Works excellent void Label_Status(object sender, System.EventArgs e) { if (CheckBox1.Checked != true && CheckBox2.Checked != true) { Label5.Text = "Please select at least One Report"; } else { Label5.Text = "Request is being Processed. Kindly Wait."; } } It displays the correct label message When i change this function to the one below, the label for "else" statement does not get displayed. Meaning lets say no checkbox is selected, the label will have "Please select at least One Report". Works. But when one of the checkbox is selected, in debug mode, it goes through both the "else" statement but i doesnt print out "Request is being processed..." But the code above is without the "Button1_Click(sender,e);" statemet and it prints out the correct label. But this one below, does not. void Label_Status(object sender, System.EventArgs e) { if (CheckBox1.Checked != true && CheckBox2.Checked != true) { Label5.Text = "Please select at least One Report"; } else { Label5.Text = "Request is being Processed. Kindly Wait."; Button1_Click(sender,e); } } Im just confused Quote
Administrators PlausiblyDamp Posted October 26, 2005 Administrators Posted October 26, 2005 Could you attach the aspx and aspx.cs files in question - it may be easier to see what the problem is if the full code is available. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted October 26, 2005 Posted October 26, 2005 From reading all the posts it looks like you're trying to get the page to update a label while it's doing something - a common misconception I've seen a number of times lately. The label will not update until the page renders again, which isn't until the current request it finished. So if you update the label, and then button1_click redirects the page, you'll never see the label get updated because button1_click redirects the page before the original page is rendered. Quote
a1jit Posted October 27, 2005 Author Posted October 27, 2005 (edited) Hi, thanks for the reply .. Yea, actually in the Button1_Click function, im redirecting the user to some path where they can download file.. Response.Redirect("http://10.204.237.97/WebDirectory/Report_"+zipFileName,false) And i realized, the label gets updated after it finish executing the Button1_Click Function if i comment the Redirect Statement. So is there any way to overcome this problem. I mean update label while processing the "Button1_Click Function" Because im just trying to display some label like "Please Wait, Request is being Process" when user click a button while the program is processing the request Thank You Edited October 27, 2005 by a1jit Quote
bri189a Posted October 27, 2005 Posted October 27, 2005 What I do when I need the user not to click anything else is I change the innerHTML of the form element to simply say Please Wait... after the form is submitted... this effectively removes the content from the screen (as the user it sees it) but allow the server to get what it needs. I have it built in my base class that I use on all my web pages since this is something I come across pretty often. Quote
a1jit Posted October 28, 2005 Author Posted October 28, 2005 Hi, I dont really get the idea Do you have any short example and reference one the explanation stated above.. Thnk you very very much Quote
bri189a Posted October 28, 2005 Posted October 28, 2005 If you goto a little church web site I made you can see an example (open the bible) http://www.salemumcwidewater.org If you look in the view source you'll see that I've changed the javascript postback method to include a call to a javascript function (this is also in the form onsubmit element). That javascript function replaces the inner text of the form element so the user can't click on something else or screw up the request process. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.