I'm using asp.net user control in my web page. I used asp.net repeater control on the user control & created one property of user control.And depending on the value of the propery i loaded the datasource property of repeater control on user control at page load event.
Then i used the userc ontrol on the another asp.net web page & set the property on the page load event. after that it is loading the datasource of repeater control of the user control.
Again I have set the user control property on the text changed event of the text box which is placed on the another web page. I want to again load the datasource of repeater control of the user control depending on the value entered in the text box. How to handle this?
Use OnTextChanged event to bind you repeater, after event fire use __doPostback event and pass some value to it, so that when its postback you can find that value and identify that this post back is done from textchange in IsPostBack event or even you can pass the page event in __doPostBack which will fire automatically then that event for example public void BindRepeaterOnTextChange(){}
check this link for more information
http://wiki.asp.net/page.aspx/1082/dopostback-function/
Related
On clciking a button in the page , I am adding an user control in to a place holder of the page.
The user control has a gridview which has a link button as template field and has a click event associated with it.
When I click the link button inside the gridview , the link button click event is not fired and also the user control disappears in the page.
Please suggest a solution
--You need to recreate all your dynamic controls at the early enough in the page lifecycle (page_load/page_init), so the asp.net will detect events and attach them.
try this knowledge post
http://support.microsoft.com/kb/317794
Why don't events of dynamically added user control fire on postback?
You need to recreate your dynamic controls on every postback - remember a new class instance of your page is created every postback, so any dynamic controls you created the previous time will need to be recreated.
see this article
and this one
I have many (around 20 - 30) NumericUpDown controls, that i have added in to user control and they are associated with their appropriate textboxes. These NumericUpDown controls work fine and allow me to adjust the numbers in the textboxes. However, I need to be able to calculate a quantity if items as user changes text box value (withour post back) and need to set it on a label/textbox on the webpage. My problem is that I can't find an event or another way to do those calculations when either the NumericUpDown control is pressed or when the textbox value changes. I've tried:
Using an event of the NumericUpDown control but it seems there are no events that fire when the value is changed
Using the OnTextChanged event of the textbox control, but that will not fire it seems, even when I have the AutoPostback property set to true
Calling a javascript function in the onchange event of the textbox control, but it seems that the onchange event is not called unless the textbox loses focus. The only way the user can change the value is through the NumericUpDown control and thus the textbox never has focus so this event is never fired.
Does anyone have any advice to get this to work? Just a note, I do have this contained in an update panel because I don't want a full page postback when a value in my NumericUpDown control is changed and the percentages are calculated.
Thanks ...
Via this: http://www.asp.net/ajaxlibrary/act_NumericUpDown.ashx
It has a currentChanged event that you can add an event handler for. You can also add an event handler on the textbox, using onblur (when it loses focus) or keypress (as the user types a key). Both event handlers are necessary.
To add the event handler for the AJAX control toolkit control, you add the name of the method to the OnClientCurrentChanged property on the control, or similarly named.
I have a button and a panel. When the user clicks the button it loads a usercontrol and adds it to panel.Controls. I need to bind a grid in the usercontrol when the usercontrol first loads (Page_Load) but not when the user clicks a button inside the usercontrol, aka triggers a postback in the usercontrol. I can't use Page.IsPostback because it returns true when the user clicks the main button which loads the usercontrol. What can I do?
It's primitive, but you can check for any control that caused the postback by comparing the value coming from:
Request.Form.Get("__EVENTTARGET")
This returns the uniqueID of the targeted control; check this to determine which button caused the postback, and act accordingly.
You can give the buttons inside of the user control a CommandName and check the value of the CommandName. You can also check the type on object sender to determine the control that caused the post back.
Don't forget that you will have to re-add the user control on each post back after it is dynamically created (in an event that occurs before Page Load), so you will need to implement a mechanism to determine that the user control was added in the panel.
I dynamically load one of many user controls based on which tab the user clicks. I store the selected tab index in view state. The user control has a checkbox on it that fires an OnChanged event. My problem is that if I load the user control in Page_Load, the checkbox event doesn't fire because the control didn't get created in time. If I load the user control in Page_Init, the page doesn't know which user control to load I believe because the ViewState isn't loaded yet. How can I store which user control to load AND get the events on the user control to fire?
The best strategy I've found has been to create all the controls in the Page_Init event, and set their Visible property to false (in Page_Load in your case) if they aren't supposed to be present on the rendered page.
Edit
Another option is to determine which controls to load based on some other criterion (besides ViewState). For example, if you make the current tab one of your query string parameters, that data will be available on the request during Page_Init.
When using custom template for Login control, if we add control with ID = Login and set its CommandName to “Login”, then Login control will automatically handle authentication.
Control with ID=Login can be any control that supports event bubbling.
Thus I assume this control can be either Button, ImageButton, LinkButton or any control that would contain Button, ImageButton or LinkButton and also be capable of transmitting Command event initially fired by one of the three containing Buttons?!
thanx
Yes, it looks like it can be any control that that causes event bubbling. See the page below:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.layouttemplate(VS.80).aspx