Telerik RadGrid - EditForm events when RadGrid is inside Repeater - asp.net

I have a Telerik RadGrid which uses the EditFormSettings like this:
<EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/MyUserControl.ascx" >
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
Within MyUserControl.ascx, I have a button which I'd like to trigger an event handler when clicked. The two ways I know of doing this are as follows:
OnClick="btnOkay_Click" as a button attribute, where the event handler is in the code behind
CommandName="Update" as a button attribute, where this is handled by the event handler passed into the OnUpdateCommand attribute of the RadGrid
Both of these work. However my problem is that they stop working when the RadGrid is within a user control within a Repeater ASP.NET control. In this case, the button event handlers do not get fired (in either of the methods above).
I notice that when I bind my repeater:
rpt.DataSource = Data
rpt.DataBind()
If I wrap that in a if(!Page.IsPostBack), then the edit form doesn't appear at all when I click on the RadGrid row's edit link. So I had to remove that IsPostBack check. I don't think think this is the cause of my problem, as I've tried explicitly not doing this when clicking my update button (by breaking into the debugger). I just thought I'd mention it incase it was related.
Can anyone think of a reason why this would break in a Repeater?

Found the problem with a little help from a work colleague! Turned out to be because I was binding the Repeater in Page_Load rather than Page_Init. Changing it to Page_Init resolved the issue.

Related

Disable/Enable a button inside a panel on an ascx control in a vb.net website from codebehind not JQuery

In my website I have a vb.net ascx control which contains a number of textboxes and a button. When the button is clicked I want to disable it, then perform some actions using the values of the textboxes, and then enable the button again. The problem i'm having is that i cannot disable the button.
The ascx control contains an asp:Panel, and inside that is an asp:UpdatePanel which contains the textboxes and the button. Could the asp:Panel or the asp:UpdatePanel be preventing the button being disabled? I can empty the textboxes without a problem, but nothing seems to work on the button.
I've tried
btnButton.Enabled = False
and
btnButton.Attributes.Add("disabled")
but they have no effect. Neither does setting the Visible property to false. The UpdateMode on the Asp:UpdatePanel is set to Always. I'm not too familiar with Asp:Panels or Asp:UpdatePanels so i'm guessing it's something to do with them. Does anyone know the correct way to do this?
After some more research I came across the solution. I just needed to add some attributes to my button like this:
<asp:Button ... OnClientClick="this.disabled=true;" UseSubmitBehavior="false" />
This will disable the button when it is clicked, but still allows the codebehind to run as well. When the codebehind has completed the button will be enabled again.

dropdownlist no postback

How can I make a dropdownlist with no postback - I have a dropdownlist which has code in selectedindexchanged
Basically for every indexchanged the code will connect to sql and get values then populate textboxes with values.
Here is my code
<asp:DropDownList ID="ddlSalesOrg" runat="server" Style="width: 200px;"
AutoPostBack="true" />
I want that the selectedindexchange should get hit, but it should NOT cause a full postback. If I set the AutoPostBack to false, then it won't hit selectedindexchange at all
You must choose - do you want postback or not. You can't set AutoPostBack="true" and after that stop the post backs.
If you just don't need full postback - use UpdatePanel for partial page update.
I dont get you question, do you want avoid the postback and also have the funcionality of vb/C# on every indexchanged?
Then your solution were AJAX all this time.
At this time I supose you have more knowledge about this.
But only for the register.
When you write something in the codebehing of ASP in response to an event, there you MUST be a postback (or partial postback) to achieve that code.
If you stop the postback abiously (as you said) these code is not achieved.
If you want to avoid the postback and also get some databind functionality (or any server side functionality) then you can disable the postback, handle the event in javascript, and call some AJAX function to make the databind.
key words for your next google search: ajax, dropdownlist,asp
Good luck to the next guy who has this problem.
You need to set the AutoPostBack property of the list to true.
Also, if you're populating the contents of the drop down list from the code behind (getting the contents of the list from a database, for example) - make sure you're not re-binding the data in every postback.
Sometimes people are caught out by binding the drop-down in the page load event without putting it in an If Not IsPostBack. This will cause the event not to fire.
The same is also true of repeaters and ItemCommand events.

Asp.net - button onclick events not raising

I'm a rookie in .net. I'm using an AjaxToolKit Accordion Control and when I put a button in, the "onclick" event is not raising. When I use a dropDownList, if I select "autoPostBack", the event raises normaly (instead, nothing occours). But with buttons I cannot define the "autoPostBack" (its implicit?). It's bringing me several troubles.
Thank you if you can help.
I've discovered the problem (moreover two problems): I'm using AjaxControlToolKit MaskEditExtenders and MaskEditValidators, and a PopUpControlExtender. When the form isn't fulfilled correctly, the MaskEditExtenders/Validators somehow disables form submiting. Also, TargetControlID property of popupControlExtender was set to the button in question. In this case, the event isn't raised.

Repeater Item Command Causes Validation

I seem to have a bit of a bug, I have a ASP.NET repeater control with a link buttons in it and the link button has the have the causes validation property set to false.
However; when clicking it which makes a panel visible on the web page, the asp.net required field validator controls trigger and shows their error messages. On those controls that I have the validator controls on.
Any ideas as to what might cause it to be ignoring the causes validation property set to false?
On my opinion, you should set different ValidationGroup properties values for repeater control and for control that is the source for required field validator. It is possible that container for repeat control has raised event that can be heared by required field validator.
If mentioned above cannot help then try to disable client validation for RequiredFieldValidator using EnableClientScript="False" for it. And activate RequiredFieldValidator when it really usefull. For example in the some button event handler you can apply such code:
MyButton.Validate();
if (MyButton.IsValid)
{
Do what you want...
}
For anybody that has this problem and stumbles across this post, here's what I found.
Turns out the problem was happening because I had EnableViewState="false" set on the Repeater. This was breaking the event postback somehow, and making every validator on the page fire. All I had to do was manually call DataBind() on the Repeater from within Page_Load(), and it cleared right up.
try to set the visablity of the panel true all the time in design view,, and check the validation again.

Events from inside a DataBound Control

I have an asp:Repeater with an asp:DropDownList in it. The DropDownLists in the repeater raise their SelectedIndexChanged events on every postback, regardless of whether they were changed or not.
Is this a known issue in ASP.NET? Do you know how to work around it?
I found this workaround but would like something prettier if at all possible.
Ah I found it - I was adding the event handler in codebehind, but when I moved it to the OnSelectedIndexChanged attribute of the asp:DropDownList control in the ASP.NET markup everything started behaving correctly.

Resources