Having issues with the .Visible property of a text box - asp.net

I'm working on a web application where a user can order a custom portrait drawings by making choices from a variety of radio button lists. There is an extra charge if they want multiple people in the portrait, so one of the questions is whether or not there will be an additional person. They can select either "Yes" or "No" from a radio button list (the choices are currently in that order, with Yes at index 0 and No at index 1). If the user selects No, nothing happens and they move on to the next question. But if they click yes, a text box whose Visible property is currently set to False appears and they enter the number of additional people.
The problem is that I can't get my text box to become visible. I currently have my TextBox.Visible = True line of code under the radio button list's SelectedIndexChanged event handler. Here's the whole subroutine:
Protected Sub RadioButtonListAdditional_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles RadioButtonListAdditional.SelectedIndexChanged
Dim characters As Integer
If RadioButtonListAdditional.SelectedIndex = 0 Then
txtAdditionalChars.Visible = True
characters = CInt(txtAdditionalChars.Text)
additionalprice = characters * 5
ElseIf RadioButtonListAdditional.SelectedIndex = 1 Then
additionalprice = 0
End If
End Sub
additionalprice was declared earlier. The rest of that just has to do with the pricing scale for the additional characters. Anyway, I feel like I'm really close to having it right and that I'm just missing something small - my VB is a little bit rusty. Any suggestions?

Have you set AutoPostBack = True on your RadioButtonListAdditional object?
Or you may need to check whether you have code on Page_Load event that call
txtAdditionalChars.Visible = False
Please let me know if this helps

In VB Net .. Radiobutton control ..
Do it in your Radiobutton CheckedChanged event .. something like this
if rb.Checked then txtbox.Visible = True

Related

Button.Enabled and checkbox.Checked status erased when redirecting on event ASP.NET VB

In my register page I have a checkbox (chkAgree) next to the terms of agreement. The register (btnRegister) button is disabled until chkAgree.Checked = True. Since the registration section is toward the bottom of the page I want to redirect the user to an anchor tag during the event. I can't seem to accomplish this without one of the two objects in question losing their status. I tried creating a Session for each object and then calling them on the page load event with no luck. I am obviously doing it wrong, but could someone please point me in the right direction? btnRegister's default status is set to Enabled=False. Here are the two methods I am using
CheckedChanged:
Protected Sub chkAgree_CheckedChanged(sender As Object, e As EventArgs) Handles chkAgree.CheckedChanged
Session("Agree") = chkAgree.Checked
Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False)
End Sub
And Page_Load:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Session("Agree") = True Then
btnRegister.Enabled = True
chkAgree.Checked = True
Else
btnRegister.Enabled = False
chkAgree.Checked = False
End If
End Sub
I have tried several different combinations of If statements but cannot figure it out without taking Response.Redirect("~/ExteriorStudentTestimonials.aspx#register", False) out.
This might be related to the fact that you're reloading the page. You might want to take a look at the following question for some ideas of how to jump to an anchor without a full redirect: Programmatically scroll to an Anchor Tag
On a different note, jumping to an anchor when the user clicks a check box doesn't sound like a very good user experience. You might consider making your form shorter.
Got it using this method similar to the ones described in the link you provided
Page.ClientScript.RegisterStartupScript(Page.GetType(),
"navigate",
"document.getElementById('register').scrollIntoView();",
True)

Panel Controls[i] - index out of range

I have a panel Profiles List on a web page. It contains multiple small panels, like a list of items contains lines. The items here are profiles. Each profile is actually a small panel SingleProfile with checkbox inside. Checkbox is the core here, because it has an ID, which is used to find the same items.
On this page there is also another similar big panel. I should add to the second panel only those items, which do not exist in the first one. So, the task is to show in the second panel only those profiles, which are not presented in the first panel. This is checked using IDs of the checkboxes in both lists.
To check if a newly added profile in the second panel already exists in the first panel, I try to access the ID property of each item in the first panel through Controls[] property. I do it in the cycle:
if (ProfilesPanel1.Controls.Count > 0)
{
for (int i = 0; i <= ProfilesPanel1List.Controls.Count - 1; i++)
{
//label1.Text += " "+Convert.ToString(sqlReader["chain_id"]); //Bug #2 - see Stored Procedure description
cbx1 = new CheckBox();
cbx1 = (CheckBox)ProfilesPanel1List.Controls[i].Controls[1]; //Bug #1 - here the Exception occurs
if (cbx1.ID == Convert.ToString(sqlReader["chain_id"])) //if profile already exists in the first panel
{
//Do not add this profile to the second panel
}
}
}
The exception "System.ArgumentOutOfRangeException" occurs in the line marked with "Bug #1".
I use sqlReader which takes IDs from a stored procedure. Stored procedure works fine in the Sql Server. But, when I output values of the sqlReader into a label on a web page (see comments in the code), each value is doubled, like "1 1 2 2 3 3 4 4 5 5".
Solution to BUG #1
Check number of controls and its names from quickwatch in debug mode and see, is ProfilesPanel1List.Controls[i] a panel or some other control. Choose your index correctly after checking it in debug mode.
And also you don't need to use cbx1 = new CheckBox(); line of code. Its next line of code is enough to initialize that Checkbox.
Your sqlReader code is not enough to get the actual cause of 2nd error.
For Bug#1, there is a chance that there might be no nested controls existing underneath 'Controls[i]'. So to guard against the bug, you can first check if there are any nested controls underneath the current element and then checking the type of control before type casting.
if(ProfilesPanel1List.Controls[i].Controls.Count>1 && ProfilesPanel1List.Controls[i].Controls[1] is CheckBox) //Iff you are double sure about layout structure and assured that it is not going to
//change. If changes are anticipated then again doing a foreach(..) over nested 'Controls' and type
//checking is much better.
{
//Do the type conversion etc., as per your requirement.
}
For Bug#2, what do you exactly mean by 'each value is doubled'? As I can see that you are appending to the same Label (with ID: Label1) inside the loop so, there is a chance for the text to be concatenated on every iteration. Also, please be sure as per your requirement, whether you need to manipulate same label's text or label inside nested controls of the parent panel.

RadDatePicker in RadGrid

I'm using Telerik RadGrids and I have RadDatePickers for columns with type of DateTime. However, when I want to pick a date it doesn't work at all. No errors, but it's simply not working. I've noticed that strangely I could select more days, but I want to be able to select a single day by clicking once on the given day.
I've observed that when clicking on the previous/next month I can select a day exactly as I would like, so there is a hack which might work (in my research it worked perfectly after the first postback, but before the first postback it didn't work at all):
Public Sub PageInit(ByVal sender As Object, ByVal e As
System.EventArgs)
Me.Page.ClientScript.RegisterStartupScript(GetType(TTControls.TTAjaxState),
"Page_Init_" & Me.UniqueID, "if (!(hasEndRequest)) var hasEndRequest =
false; if (!(hasEndRequest)) {var prm =
Sys.WebForms.PageRequestManager.getInstance();prm.add_endRequest(function()
{$('.rcPrev').click();console.log('clicked');});} hasEndRequest =
true;", True)
End Sub
In the code above you can see a method which will be a handler for page init.
However, I would very much like to be able to select a day by clicking on the RadDatePicker and clicking on a day. Here is how my RadDatePicker looks like:
If anybody knows the solution and decides to share it with me (if the solution is not a hack then I would be extremely happy) I would be very gladful.
Thank you in advance,
Lajos Árpád.
Will it demand a lot of work to replace your RadDateTimePicker by a RadCalendar?
The RadCalendar supports the property SelectionMode..
Have you set the SelectionMode property to Single?
Solution:
Sys.Application.add_load(function () {
$(".RadCalendar.RadCalendar_Default .rcPrev").each(function () { $(this).click(); });
});

updatepanel doesnt update correctly, must click twice to update

I am using an update panel and when I click a button it will update all the panels.
updapanel1.update() is very simple, but my data is not updating unless I hit the button twice.
My gridviews shows data for a selected user, and then all the grids reflect that users data.
works fine all the update panels work for the gridviews.
Now for somereason when i try to do a row count and update the panel with the summary, it does not work, i get either the previous users summary or if i hit update again for the same user i get the correct data.
'the grids are in these panels
UpdatePanel1.Update()
UpdatePanel2.Update()
UpdatePanel4.Update()
UpdatePanel6.Update()
UpdatePanel7.Update()
'the things that are not updateing correctly
rqnum.Text = GridView3.Rows.Count
oknum.Text = GridView4.Rows.Count
xlnum.Text = GridView5.Rows.Count
dynum.Text = DataList1.Items.Count
UpdatePanel8.Update()
Panel1.Visible = False
Without seeing the code for this we cannot guarantee that we are giving you the right answer, but just a thought. If the code you posted is the actual code, I would re-order things a bit.
Do the updates to the content
Then call "update" on the panels
This ensures that your content updates are actually sent to the panels. My guess is this is why it takes that second click. So something like this.
'Update content and toggle visibility of controls
rqnum.Text = GridView3.Rows.Count
oknum.Text = GridView4.Rows.Count
xlnum.Text = GridView5.Rows.Count
dynum.Text = DataList1.Items.Count
Panel1.Visible = False
'Now update all needed panels
UpdatePanel1.Update()
UpdatePanel2.Update()
UpdatePanel4.Update()
UpdatePanel6.Update()
UpdatePanel7.Update()
UpdatePanel8.Update()

How can I trap "View Report" in ReportViewer (webforms) for SSRS?

I am using ReportViewer.WebForms in asp.net page. I have the parameter toolbar showing up where I can select a parameter, it does a postback to get the next parameter (dependent on the first), and so forth.
When I click the View Report button there is a postback and the report will display fine.
All this works great.
What I would like to do is set the ShowReportBody to false
ReportViewer.ShowReportBody = False
At this point I would like to grab all the parameters that have been selected by the user and run the render method to export to a file (of my choosing .. maybe excel, maybe pdf .. does not really matter, nor is the topic of this question).
So, my question is, how (or can I) trap the button event of the View Report button? I would like to be able to use the ReportViewer UI in order to capture all the parameters instead of building custom parameters.
I'd also like to rename this, but, again .. another topic :)
You can use the IsPostBack flag and QueryString
Example:
Viewer.ShowReportBody = false
if(IsPostBack)
{
if(Request.QueryString["Exec"] = "Auto")
Viewer.ShowReportBody = true;
...
}
else
{
Viewer.ShowReportBody = true;
}

Resources