Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Wednesday, March 28, 2012

UpdatePanel - Javascript to create control wont fire

I've got an update panel that functions like tabs, hiding/showing certain controls. One of the controls is rendered via javascript:

<script type="text/javascript" language="JavaScript">
showCategoryBox("Databases", "All Resources");
</script>

This creates a dropdown list to choose from. It works fine when the page loads, but going to other tabs, then coming back to this one causes it to disappear. All of the standard html controls show up fine, but it won't execute this script to create the dropdown.

Any Ideas? Thanks

Coop

Try something like this. The pageLoaded event of the PageRequestManager is raised after every postback, synchronous or asynchronous.

<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(onPageLoaded);

function onPageLoaded(sender, args) {
showCategoryBox("Databases", "All Resources");
}
</script>


Thanks. I tried this (and something very similar by using ScriptManager in the cs file) and it just basically only shows this drop down, nothing else on the page shows up. The page starts to render, then everything goes blank and only this shows up at the top.

Monday, March 26, 2012

UpdatePanel + Infragistics Treeview

I am trying to create a very simple UpdatePanel + Treeview page. The data is initally loaded (via code, recursive nodes added in code behind) the tree loads fine.

As soon as I click on a node (and capture the NodeClick event) the Tree view stops working and reports a Javascript error. "Microsoft JScript runtime error: 'undefined' is null or not an object"

Has anyone seen this before? Do the Infragistic controls not work with Atlas?

Thanks in advance.

Are you using the Tree's Automatic SmartCallback LoadOnDemand behavior, or Manual LoadOnDemand? I would recommend using the Tree's own AJAX enabled LoadOnDemand functionality, even inside of the UpdatePanel, since you really only need to update the tree. If you still have difficulty, please contact Infragistics Developer Support (http://devcenter.infragistics.com)

Also, if you have a valid Subscription, we are about to release our 2006 Volume 2 Beta. We've made some changes in order to better support Atlas, and it would be great if you could validate whether it fixes your current problems or not.

-Tony

Anthony Lombardo
Infragistics, Inc.
Product Manager | NetAdvantageASP.NET

Wednesday, March 21, 2012

UpdatePanel and RadioButtonList

I have a radiobuttonlist with three options. I want them to update, add or delete options within a dropdownbox, via an Update Panel, when they are changed.

My code is:

<asp:RadioButtonList ID="radType" runat="server" RepeatDirection="Horizontal" RepeatColumns="3" AutoPostBack="true" OnSelectedIndexChanged="UpdateDropDown">
<asp:ListItem Text="Option 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Option 3" Value="3"></asp:ListItem>
</asp:RadioButtonList>

<asp:UpdatePanel ID="pnlDropDown" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:dropdownlist id="ddlTest" Runat="server">
<asp:ListItem Value="0">List one</asp:ListItem>
<asp:ListItem Value="1">List two</asp:ListItem>
<asp:ListItem Value="2">List three</asp:ListItem>
<asp:ListItem Value="3">List four</asp:ListItem>
<asp:ListItem Value="4">List five</asp:ListItem>
</asp:dropdownlist>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="radType" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>

I have set Option 1 of the RadioButtonList to be selected when the page loads. If I then change the radiobuttonlist to Option 2, it all works OK. But any change after that generates the following error message:

"Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or%@dotnet.itags.org.Page EnableEventValidation="true" % in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."

I have tried various fixes without any results. I have tried putting the RadioButtonList in an update panel also. Didnt help. I have tried putting in a hidden button and linking the click events to the button click event (as in posthttp://forums.asp.net/p/1015714/1364825.aspx). Didnt help. I have tried registering all events. Didnt help. I've tried separate radio buttons rather than the list. Didnt help. Anything I try always ends up back at this error message.

Does anybody know how I can get this to work?

Thanks in advance.

Hi,

This exception is typicaly thrown if your UpdatePanel is not updated and old value of the dropdown is sent to the server. Plase add to your UpdateDropDown method a call to

pnlDropDown.Update()

This call willensure that your panel is updated. Does it help? Do you have any other DropDowns on the form? Do you change any other controls during the async postback?

-yuriy

http://couldbedone.blogspot.com


Hi Yuriy

Thanks for your response. I have tried your suggestion and unfortunately it doesnt seem to have made a difference. Does it matter where the Update call is placed? Before or after I change the values - or both?

In answer to your other questions - this is the only dropdown on the form, and I do have one other update panel on the form that changes another set of controls. The page also has a master page, not sure if that is muddying the waters as well.

The only way I have got this working is to disable PageEventValidation, and wrap the RadioButtonList in its own UpdatePanel. Further searching after my post seems to indicate this is the only way to resolve this, and, like me, everyone is not happy that this is the only solution!! But at least it works. But if anybody knows of a way to achieve this without disabling PageEventValidation, I would be most interested to know how to do it.

Thanks again.


Hi

what you described makes me think that the problem is with another update panel and probably some other control.

Yesterday I tried to describe a technique to find the control causing the problem. Try following instructions athttp://couldbedone.blogspot.com/2007/09/conditional-updatepanel-and-event.html

-yuriy


Thanks for the link Yuriy. I've had a try to identify which control is causing the problem, but I've not had a lot of luck. Neither has calling the Update function helped. So I've stuck to disabling event validation for now. Thanks for your help though, I will certainly bear your post in mind in future Ajax dealings!


Hi,

I've just encountered the same problem as you. I've found a solution inside the code behind.

You need to be careful with the Page_Load. Indeed inside this method you might do initialisation to your dropdown or other control.

So add this inside:

if( !IsPostBack || !IsAsync)

{

//Initialisation code for your form

}

Then you will see that your conditional updatepanel is working.

Hope that will answer,

Kind regards.


Hi dojaju,

Thanks for your reply and glad to hear you got it working. Unfortunately I cant seem to be able to get it working on my code. I did already have an !IsPostBack in my Page_Load to first set the dropdownlist to the first option, and adding the !IsAsync just seems to effectively cancel out the !IsPostBack, so every PostBack it just resets the dropdownlist to the first option. I've tried a few different options with the IsAsync but nothing seems to have worked.


Hi,

I've check again your sample code and i've seen something interesting concerning your dropdownlist. So i've made a little something without the dropdownlist information inside the aspx page.

I will add it in code behind so i'm free to do what i would like later with an event.

1: aspx page

<divstyle="text-align: center">

<asp:RadioButtonListID="radType"runat="server"RepeatDirection="Horizontal"RepeatColumns="3"

AutoPostBack="true"OnSelectedIndexChanged="UpdateDropDown">

<asp:ListItemText="Option 1"Value="1"></asp:ListItem>

<asp:ListItemText="Option 2"Value="2"></asp:ListItem>

<asp:ListItemText="Option 3"Value="3"></asp:ListItem>

</asp:RadioButtonList>

<br/>

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">

<ContentTemplate>

<asp:DropDownListID="DropDownList1"runat="server">

</asp:DropDownList>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="radType"EventName="SelectedIndexChanged"/>

</Triggers>

</asp:UpdatePanel>

</div>

2: c#

protectedvoid Page_Load(object sender,EventArgs e)

{

if(!IsPostBack && !IsAsync)

{

Init_DropDownList();

}

}

protectedvoid UpdateDropDown(object sender,EventArgs e)

{

// Test your Radiobutton and as the radio option are selected do something to the dropdownlist.

}

protectedvoid Init_DropDownList()

{

// Create the list of option to place inside the dropdownlist

}

protectedvoid DDL_ActionToDo(string Action)

{

switch (Action)

{

case"1":break;case"2":break;

}

}

As you can see, in the first page load i do the init of the dropdownlist, and it won't come again since the user is not going out and back to this page.

And so the state of all the control won't be a trouble for your async.

Hope that is helping you.

You can send more informations of your project if you like to.

Kind regards,


Im sorry, I've tried that and it still doesnt work! Surely the problem is that the control has changed since first load, and your solution is only mimicking adding the listitems on the page anyway? I tried moving the dropdown load function to before the controls get registered for event validation, in the hopes it would pick up the new list, but that hasnt helped either.

Im sorry I havent been able to implement your suggestions, and I truly do appreciate your help.


Can you send me more about your source code??

Otherwise, I'm sorry for not being able to help you.

Kind regards,