Greetings,
I created a aspx page that uses a master page. Inside I have a control, let's say txtName and I have a submit button, that when I press it it will submit the text in the txtName to another page.
The problem is that the Request.Form key does not have the txtName, instead it something like clt00$Container0&txtName.
Isn't there a way to easily find the key that I want to retrieve from there?
You can implement the behaviour via Cross Page Postback. Then you can access the value via PreviousPage.FindControl("txtName") or via a custom property (see section "Using Property to expose and Consume values of TextBox" in the linked article above)
Make sure they r with in the same form when, it
renders onthe client. If not u will not get on server
look view source n see where u master page control
is
Related
I've created a web form programmatically using asp.net repeater, where one of the items/fields is an MSCaptcha control. On postback, I would like to validate the captcha. Been struggling to access it since the captcha field/control is inside the Repeater and this.FindControl("captchaid") returns null. Any ideas?
Also, I am able to access all the form values including captcha text through Request.Form["field id"]. What would be nice is to be able to actually validate the captcha and not just capture the value.
If you're using this.FindControl (as stated) you will search for controls in the current page or usercontrol, not in the repeater item. You will need to loop through the repeater items and perform the FindControl on the RepeaterItem instance until you find your captcha control. (Or google to find an implementation of FindControl that is recursive, though I would say this is probably less optimal).
I have a page index.aspx this page has two Web user Controls, list.ascx and display.acsx basically list.ascx shows all the lists that are available on that SharePoint site into a dropdown box. The second web user control, displays a list of all the files in the list selected. But there's where I run into the problem my question is how do I transfer the value of the dropdown box from the first web user control into the second one.
thanks
Given that you are using custom web controls, it's a bad idea I find, to intrinsically link two different controls together as dependents. Instead:
Define an event on the first control that is raised appropriately with event arguments containing the data.
Have the encompassing index.aspx page have a handler for this event.
Within this handler, set an appropriate property on the second control, passing the data from the event argument.
This is much cleaner, achieves what you want and de-couples the two controls from one another.
Your list.ascx needs to postback the ListId to the server when the value is changed
<select onchange="PostBackWithListId();" >
<option value="SomeListId">
</select>
jQuery could help here, or you could do it server side with OnSelectedIndexChanged and AutoPostBack.
Then your display.acsx, just needs to read the ListId from the request.
If you just want to pass the data once brutally, no strings attached:
make a class with a static member of the type of data you want to pass.
set the value in one ascx file and read in the second ascx file..
I have a user control with this OutputCache:
<%# OutputCache Duration="86400" VaryByControl="LnkBtnTopVanzari" %>
Where VaryByControl is the id of a link button i use to switch the active view of a multiView contained in an updatePanel.
The problem is that when i press that link button, the page does a full post back and the view is not switched.
If i remove the outputCache directive, all works great (pressing the link button the correct view is shown via ajax).
Do you know where i am wrong?
Thanks.
The VaryByControl parameter is used to vary depending on the value of the control which you specify. As the value of the link button will always be the same, the cache is not varied.
I believe this is intended to be used for controls such as dropdown lists, where it is feasible for the output to be different based on the selected value in the list.
You may want to try using VaryByParam and changing your link button to a hyperlink, specifying the view as a query parameter, or trying out VaryByCustom. Otherwise possibly you could possibly split the content of your views into separate user controls which are themselves output cached, leaving the multiview and your link button outside any caching.
What would be the best approach to set dynamic content from the database to controls in an aspx page?
My database consists of pages (index.aspx, home.aspx and so on) which consists of controls (DivStart, LabelDescription, and so forth).
The first technique that came to my mind was looping through all the controls in the page, looking for controls that have a certain class, e.g. "Cms_DivStart", and would then set the inner html for that control from the database control called "DivStart". The problem is only runat server controls shows up, and I don't want to make all controls server side.
I could store all the dynamic texts for a page in hidden variables and set it with jQuery when the page has loaded, but that would make the text not show up directly..
Any other ideas would be greatly appreciated.
Thanks
/Andreas
You could use asp:PlaceHolder tags, these don't add any html unless they are utilised.
You can write a custom class, I'll call it "CustomPage", that inherits the System.Web.UI.Page class. Then your pages can inherit "CustomPage". In this class, add methods to retrieve data, set custom properties and display your content in the available controls.
I am using c#.net
I have different views within my webform, these all generally display different information except for three textboxes (arrival / seen / depart time). To try and cut down on code, I have created a UserControl which contains these three textboxes.
I have referenced the UserControl at the top of my webform and also within each view.
<%#Register TagPrefix="uc1" TagName="userTimes" Src="~/usercontrols/userTimes.ascx"%>
<uc1:userTimes id="userAppointmentTimes" runat="server"></uc2:userTimes>
can’t seem to access the textboxes from the code behind. I need to firstly populate the textboxes and also hold any updated information to be re-inserted back into the database if changed.
Also each textbox has two Validation controls:
First makes sure it is in time
format HH:MM
Second makes sure the arrival is
before the seen time etc
My two questions are:
How do I access the UserControl from
the code behind? I have read that I
need to use the FindControl but I
don’t understand why, when I know
what it is called.
Do I undertake the validation
(server side) within the UserControl
code behind or the webform code
behind?
Thanks in advance for any help.
Clare
1.) You can access the User Control by its ID from the page's code behind - userAppointmentTimes in your case. To access your TextBoxes within the webform you need to use the FindControl-Method at the User Control level. So something like userAppointmentTimes.FindControl("WhateverTextBoxID") should work. You need to cast the result to TextBox of course.
You can't access the text boxes because ASP.Net does not automatically expose them for you. So alternatively you can provide public properties to set/get values to/from your textboxes inside your user control.
Within the user control, you can access your textboxes by their IDs.
2.) Put the validation controls inside your user control.
By webform you mean it's all inside the asp.net form-tag or do you have an asp.net form like FormView nested inside? If the latter is true you need to use FindControl at the FormView level - formView.FindControl("userAppointmentTimes"). Otherwise the user control is accessible from page level via its ID.