Showing posts with label postback. Show all posts
Showing posts with label postback. Show all posts

Wednesday, March 28, 2012

Change TimerControl Interval property without postback

Hi,

I have a "Live monitor" scenario, where data in UpdatePanel is being updated on TimerControl tick.

I want to give user an ability to change interval. It works fine, but postback is needed to do so.

Any way to do it without a postback?

(I'm new to atlas, so please excuse me if it's obvious.)

hello.

well, if you're ready to build your own timer, then it's possible to do that in the client side. currently, the problem is that the timercontrol generates a client behavior but doesn't generateou an id. due to this, you cannot get a reference to the behavior in the client side and do need to do a postback to refresh that interval.

Change the default async timeout error message

I can't believe this question hasn't been asked before... How do I change the message that is displayed to the user when an async postback has timed out? I've searched the scriptmanager documentation and tried to handle the asyncpostbackerror or whatever event (which doesn't fire on a timeout), but I can't figure out how to do it. Any hints will be appreciated. Thanks.Hi,

You can add your own error handler as the following code:
function StartAsyncPostBack() {
WebService.set_timeout(2000);
WebService.RunForLongTime(0, Complete, OnError); // call a method with the signature of?RunForLongTime(int);
}
function OnError(result) {// your error handler
alert("error: " + result.get_message());
}

Hope this helps.

Change full postback action from inner update panel...

Hi,

Is there a way to alter full postback to partial postback caused by outer update panels from usercontrol?Huh?Confused...I tried to add button control as an AsyncPostBackTrigger. No effect to change from a full page postback to partial one. No change whether I set properties like ChildrenAsTriggers to false/true and UpdateMode to Always/Conditional inner update panel, when a button or any control causes a postback action is pressed, it causes a full postback.


Parent:

<asp:UpdatePanel ID="upanelPage" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<asp:UpdatePanel ID="upanelMainContent" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<!-- Main Content --> <<-- my user control or other are displayed
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>

User Control loaded to Parent...

<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<ajaxToolkit:TabContainer ...>
<ajaxToolkit:TabPanel ...>
<asp:MultiView...>
<asp:View...>
...
<asp:LinkButton...></asp:LinkButton>
<asp:Button...></asp:Button>
<asp:UpdatePanel ...>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=.../>
</Triggers>
<ContentTemplate>
...
<asp:GridView...>
</asp:GridView>
...
</ContentTemplate>
</asp:UpdatePanel>
...
</asp:View...>
<asp:View...>
...controls...
</asp:View>
</asp:MultiView>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ...>

</ajaxToolkit:TabPanel>
...
</ajaxToolkit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>

UpdatePanel causes a Full Post Back no matter what properties you set on it.

If you are looking for better performing alternatives, look out for ScriptCallbacks or JSON Based Calls and this would require "some" work compared to ourmagic updatepanel!


Huh??ConfusedScriptCallbacks?ConfusedJSon Based Calls?Hmm...Does not know what are they or how to start with them? ..thanks for the reply..


Huh??ConfusedScriptCallbacks?ConfusedJSon Based Calls?Hmm...Does not know what are they or how to start with them? I was trying to control the postback action of outer update panel from the inside user control..thanks for the reply..


Hi,den2005

I found that the following code worked.

The Page:

<%@. Page Language="C#" %>

<%@. Register src="http://pics.10026.com/?src=WebUserControl2.ascx" TagName="WebUserControl2" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Tutorial</title>
<style type="text/css">
#UpdatePanel2 {
position: relative;
margin: 2% 5% 2% 5%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ChildrenAsTriggers="False" ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<fieldset>
<legend>Parent UpdatePanel</legend>Last refresh
<%=DateTime.Now.ToString() %>
<br />
<asp:Button ID="Button1" runat="server" Text="Refresh Outer Panel" />
<uc1:WebUserControl2 ID="WebUserControl2_1" runat="server" />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

The UserControl:

<%@. Control Language="C#" ClassName="WebUserControl2" %>
<asp:UpdatePanel ChildrenAsTriggers="False" ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<legend>Nested UpdatePanel</legend>Last refresh
<%=DateTime.Now.ToString() %>
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Calendar1" />
</Triggers>
</asp:UpdatePanel>

Hope this help.

Best regards.

Jin-Yu Yin

Monday, March 26, 2012

causing validation from client side without postback?

Now that I added callout extenders to my validators how can I get them to work 1- on the client before calling an AJAX webservice and 2- in the webservice? I am not using an update panel so can I turn off server side validation and write my own for the webservice to call?

Hi Echo,

Echo88:

Now that I added callout extenders to my validators how can I get them to work 1- on the client before calling an AJAX webservice and 2- in the webservice? I am not using an update panel so can I turn off server side validation and write my own for the webservice to call?

My understanding of your issue is that you want to validate the inputs. If all these are correct then call the WebService ,otherwise, show the error message by using ValidatorCalloutExtender. If I have misunderstood, please feel free to let me know.

Validators are call before the form is submitted , but to call the WebService we don't need to postback. So I suggest that you should write your own validate Javascript code instead of ValidatorCalloutExtender controls.

Here is the sample to call a WebService.

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="DataTableService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager
<input type="button" value="Get DataTable" onclick="getDataTable();" /
<div id="result"></div
<script language="javascript" type="text/javascript">
function getDataTable()
{
DataTableService.GetDataTable(onSucceeded, onFailed);
}

function onSucceeded(result)
{
//handle code
}

function onFailed(error)
{
//handle code
}

You can also transfer all the inputs and validate on the server side in the WebService.

I hope this help.

Best regards,

Jonathan


Thanks - sucks that I can not use those jazzy callouts. But a question I have is - doesn't it call a client script prior to postback?? My understanding is that validation takes place before posting the form data to the server, so one would think there is a call to a script that precedes the actual postback. Am I wrong?


Hi Echo88,

But a question I have is - doesn't it call a client script prior to postback??

Yes , you are right. The problem is that if all the inputs are correct , the form will postback next. But to call a webservice , we usually do not need to postback. It will cause the page refreshment. Based on this , I think write your own Javascript function is a better way in this situation. If you don't want to validate on the client side , you can also transfer all the inputs to the server side and validate on the WebService.

function setBoy()
{
var boy = new Object();
boy.Name = "Terry";
var girl = new Object();
girl.Name = "Mary";
boy.GirlFriend = girl;

BoyGirlService.SetBoyWithGirlFriend(boy, onSetBoySucceeded, onFailed); // call the WebService.
}

I hope this help.

Best regards,

Jonathan


exactly - I am calling a webservice instead of a postback. But am I right to say there should be a way to cause validation on the client - regardless of postback? I just thought there would be a method to execute independently. What aboutPage_ClientValidate() ??


Hi Echo88,

Yes , I agree with you. You can use it like this.

Button1.Attributes["OnClick"] = "Javascript:if (typeof(Page_ClientValidate) == 'function') if(Page_ClientValidate()) {return confirm('Are you sure to submit ?'); } else return false;";

Best regards,

Jonathan


I tried that - no dice. The button is set to cause validation and uses submit behavior. However, nothing is happening? I guess it is not finding Page_ClientValidate function. When include Page_ClientValidate by itself - it throws an error. So why is not included?


Hi Echo88,

Sorry for the delay. Here is my test sample and it works pretty well.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Button1.Attributes["OnClick"] = "Javascript:if (typeof(Page_ClientValidate) == 'function') if(Page_ClientValidate()) {return confirm('Are you sure to submit ?'); } else return false;"; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"><%=DateTime.Now.ToString()%> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="true" CausesValidation="true" /> </form></body></html>
So please compare it with yours and if it doesn't work, please feel free to let me know with more information. Thanks.

Best regards,

Jonathan


Your example works - even though it does perform a postback - I turned off the submitbehavior. Still works:) so there is hope- I suspect the

Page_ClientValidate function is not getting generated somehow. Could the fact that I am using them all as part of a user control be the problem?
Thanks - its really appreciated. 

Ok - I found out something interesting... The Page_Validators array is not populating on this one page. Any ideas why they are not populating Page_Validators ?


OK - I found the root of the cause. In my control I have readonly mode that would make all validators invisible if it was in readonly mode. Apparently, I did set the function incorrectly and all validators were not being rendered.

Causing postback

I have written some javascript that async calls a webservice every second. If the service returns true, I want to cause a postback, with client script that can be handled on the server and tell a particular update panel to update in the server side handler.

I also wish to construct event arguments on the client to be passed as part of the post back.

How do I do this?

I need to do something similar, and I'm wondering if you could do it by having your page implement the IPostBackEventHandler. This interface requires that you implement a RaisePostBackEvent method. This method takes a string argument, and you could update your updatepanels in this method. Does anyone know if this approach would work?

Thanks,

Nick


hello.

ipostbackeventhandler is not the answer if you need to update updatepanels. what you could do is:

1. use the postbackaction

2. add a hidden dummy button to the updatepanel and force the submit by calling its click method


Nope, dont need to do that. ipostbackeventhandler is the way to go.

I add some javascript to the page via:

Microsoft.Web.UI.ScriptManager.RegisterClientScriptBlock(
this,
this.GetType(),
"UIService_Agent",
string.Format(
"function CheckAgentTimer()" +
"{{" +
"UIService.ShouldInteruptAgent(OnAgentTimerSucceeded,OnAgentTimerFailure);" +
"}}" +
"function OnAgentTimerSucceeded(result)" +
"{{" +
"if(eval(result))" +
"{{" +
"{0};" +
"}}" +
"setTimeout(\"CheckAgentTimer()\",{1});" +
"}}" +
"function OnAgentTimerFailure()" +
"{{" +
"setTimeout(\"CheckAgentTimer()\",60000);" +
"}}" +
"setTimeout(\"CheckAgentTimer()\",10000);",
this.Page.ClientScript.GetPostBackEventReference(this,AgentTasksTimer.AGENT_PROCESS),
this.timerInterval
),
true);

and then I implement the interface ipostbackeventhandler


public void RaisePostBackEvent(string eventArgument)
{
if (eventArgument == AGENT_PROCESS)
{
//Is There Work for the Agent?
if (WorkItemActionRequired != null && IsWorkItemActionRequired())
{
WorkItemActionRequired(this, new WorkItemEventArgs(ResourceReceiverService.GetUserWork(((IUserPrincipal)Context.User).Credentials.UserId, true)));
}
}
}

Messy I know, but bare with me...

You can then request that update panels are updated on the server i.e. myUpdatePanel.Update

This works!


Luis Abreu:

hello.

ipostbackeventhandler is not the answer if you need to update updatepanels. what you could do is:

1. use the postbackaction

2. add a hidden dummy button to the updatepanel and force the submit by calling its click method

How do you call the click method on a hidden dummy button?


hello.

you must get ?a refernce for the html control and call its click method:

$get("your_button_client_side_id").click();

But will this cause a partial or full post back?

Thanks,

Nick


hello.

it depend: if it's an asp.net button and it's placed inside an updatepanel (or if it's outside the updatepanel but it's configured as a trigger) you'll get a partial postback.

That might do the trick then. Right now I have implemented IPostBackHandler, but it causes a full post-back. I just want to do a partial. How do I make the button invisible, set Visible to false, or set visible to hidden in the button style?

Thanks,

Nick


hello.

it depend: if it's an asp.net button and it's placed inside an updatepanel (or if it's outside the updatepanel but it's configured as a trigger) you'll get a partial postback.
hello again.
well, i'd just add syle="display:none" in the asp.net button declaration.

This will also allow me to put code server-side?

Thanks,

Nick

Causing Async Postback after closing ModalPopup

Hey,

Im trying to make use of the ModalPopupExtender in order to allow the user to input some information and then have an UpdatePanel async postback to update with this new information. The key here would therefore be to Update the Panel right after closing the ModalPopup. This is where Im having some troubles. No matter what I cant get the UpdatePanel to postback after clicking Ok from the ModalPopup. As of right now, once you click Ok from the Modal, you have to hit refresh in order to see the results of the info... which kinda defeats the purpose of AJAX.

Thanks in advance for help!

Hi,

You can first add an invisible button on the form, and set it as the triggerfor the UpdatePanel.

Then, add a OnOkScript to the modalPopupExtender. In the script, call click on the invisible button. Like this: $get("id of the invisible button").click

So, whenever the modalPopup is closed via clicking on ok button, the UpdatePanel is able to update.

Hope this helps, and please feel free to let me know if there is any problem.

Cause Postback with a Clientside Javascript

Hello,

I'm attempting to, with use of Clientside Javascripts (called from a Flash movie), to cause a Postback that will allow me to update the content of a GridView on my ASP.NET AJAX Page.

I've spend a lot of time looking at the documentation for the clientside framework, but I haven't been lucky enough to find anything. I realize that this poses the problem of a control having to cause a postback - but is there some way to do this (some workarround)?

Regards,
Jonas

Hi Jonas,

The way I do it (and I'm not sure it's a best practice / it is certainly a workaround ;) ) is the following:

To cause a postback: let the javascript find a button on the page (a server-side button) (for example: document.getElementById('MyButton')

Then you can touch the click event of that button

Make that click event cause a full postback or a partial postback (callback) if the button is a trigger of an updatepanel.

I hope all makes sence.
If you have further questions/remarks I'd like to hear them.

Greetz
Wim


HI Jonas,

You can write a javascript function withdocument.aspnetForm.submit(); statement in it and call it from your Flash. This will cause a postback and you can update the content.



A call to Sys.WebForms.PageRequestManager.getInstance()._doPostBack() is a good way to do it.

Cause a JavaScript Function to run after update (update panel postback)

Hello,

I ran into a problem that im not sure if the Atlas framework addresses.

I need to fire off a javascript function (which is decided server side)on a postback. To do this I am going to be using a hidden input field.(since I already have one on the form I use to send information forserver use.) From the server side, I can place the function names intothe hidden input field. But I can't cause them to run, on each postback.

I suppose that is confusing, let me try something simpler.

1. I fire off a postback in javascript - This is done using the__dopostback() and the server side fires off its if statements and doesits functions based on what has been placed into my hidden input field.(this is all good so far) (if I had to I could use the body's on formload ability to fire off the javascript functions I desire, but thatwont work for the next step, and is really ugly)

2. I include Atlas to make my postback not refresh the whole page. This is done by using UpdatePanels.

3. On the server side I need to somehow tell it to run certainjavascript functions when that postback finishes loading. (so like onpartial page load)

How do I do step 3?<script type="text/javascript">
function AfterPostback()
{
alert("This is where we check the hidden input and run the functions.");
}

function PageRequestManagerPropertyChanged(sender, args)
{
if (args.get_propertyName() == "inPostBack")
{
if (!$object("_PageRequestManager").get_inPostBack())
AfterPostback();
}
}

function pageLoad()
{
$object("_PageRequestManager").propertyChanged.add(PageRequestManagerPropertyChanged);
}
</script
<div>
<atlas:ScriptManagerEnablePartialRendering="true" ID="ScriptManager1" runat="server">
</atlas:ScriptManager>
<atlas:UpdatePanel runat="server" Mode="Conditional" ID="UpdatePanel1">
<ContentTemplate>
<%= DateTime.Now.ToLongTimeString() %>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger ControlID="UpdateTime" EventName="Click"/>
</Triggers>
</atlas:UpdatePanel>
<asp:Button ID="UpdateTime" runat="server" Text="Update Time" />
</div
Thats the solution I rigged up.
Hi,

Thanks for posting your solution. It works very well and solves a whole bunch of missing stuff with AtlasPanels. One problem dough. I had to move the call to JS function pageLoad() to the end of the html file part instead of putting it to body onload event.
Another option for doing this is theUpdateProgressSignup extension.

Catching key press events. For example username control without postback

Hi atlas developers and implementers,

For example I have a textbox and I want that on every key press the written string will be controlled from database and it should say whether it is found on database or not. I'm using atlas 2.0. It is like username control without postback.

How can I do this..

Kind Regards,

Fatih U?AR.
Postglobal Ltd.
R&D ManagerHi,

basic example + bonus behavior:

<%@. Page Language="C#" %><%@. Import Namespace="System.Data" %><%@. Import Namespace="System.Web.Services" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private DataTable data = null; protected void Page_Load(object sender, EventArgs e) { BuildData(); } private void BuildData() { data = new DataTable(); data.Columns.Add(new DataColumn("Username", typeof(string))); data.Rows.Add("garbin"); data.Rows.Add("leoscorpio82"); } [WebMethod] public bool CheckForUsername(string username) { bool userExists = data.Select("Username = '" + username + "'").Length > 0; return userExists; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="sm" runat="server"></atlas:ScriptManager> <div> <span>Username:</span> <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox> </div> </form> <script type="text/javascript"> function txtUsername_Keypress(sender, e) { PageMethods.CheckForUsername($object('txtUsername').get_text(), onCheckComplete); } function onCheckComplete(result) { $object('txtUsername').get_style().backgroundColor = (result) ? '#ffffff' : '#ff0000'; } </script> <script type="text/xml-script"> <page> <components> <textBox id="txtUsername"> <behaviors> <keyUpBehavior keyup="txtUsername_Keypress" /> </behaviors> </textBox> </components> </page> </script> <script type="text/javascript"> // A behavior to handle the keyup event. Type.registerNamespace('AtlasExamples'); AtlasExamples.KeyUpBehavior = function() { AtlasExamples.KeyUpBehavior.initializeBase(this); // Private members. var _keyupHandler; // Events. this.keyup = this.createEvent(); // Initialize / Dispose. this.initialize = function() { AtlasExamples.KeyUpBehavior.callBaseMethod(this, 'initialize'); _keyupHandler = Function.createDelegate(this, keyupHandler); this.control.element.attachEvent('onkeyup', _keyupHandler); } this.dispose = function() { this.control.element.detachEvent('onkeyup', _keyupHandler); _keyupHandler = null; AtlasExamples.KeyUpBehavior.callBaseMethod(this, 'dispose'); } // Descriptor. this.getDescriptor = function() { var td = AtlasExamples.KeyUpBehavior.callBaseMethod(this, 'getDescriptor'); td.addEvent('keyup', true); return td; } // Event Handler. function keyupHandler() { //debug.trace(event.keyCode); this.keyup.invoke(this, Sys.EventArgs.Empty); } } AtlasExamples.KeyUpBehavior.registerClass('AtlasExamples.KeyUpBehavior', Sys.UI.Behavior); Sys.TypeDescriptor.addType('script', 'keyUpBehavior', AtlasExamples.KeyUpBehavior); </script></body></html>

hello ,

the answer is ok but where is the 'AtlasExamples' behavior

i'll be glad for you answer

kind regards,


Hi,

AtlasExamples is a namespace (defined with a call to Type.registerNamespace at the beginning of the Javascript code) while the behavior is the AtlasExamples.KeyUpBehavior class defined inside the Javascript code block (it inherits from the base Sys.UI.Behavior class).


hi garbin yes i know but i don't have the dll file of the namespace. so i can't get it work. I need necessary files.. I'll be glad if you send me the files tofatihu@.postglobal.com

regards,


Hi,

sorry, but what do you mean by "the dll of the namespace"?


I mean, I run the code you wrote but it didn't work, what should I do, it didn't validate

Hi,

ah, sorry, didn't notice that the code was written for CTPs :)

Here's the updated code:

<%@. Page Language="C#" %><%@. Import Namespace="System.Data" %><%@. Import Namespace="System.Web.Services" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private static DataTable data = null; protected void Page_Load(object sender, EventArgs e) { BuildData(); } private void BuildData() { data = new DataTable(); data.Columns.Add(new DataColumn("Username", typeof(string))); data.Rows.Add("garbin"); data.Rows.Add("leoscorpio82"); } [WebMethod] public static bool CheckForUsername(string username) { bool userExists = data.Select("Username = '" + username + "'").Length > 0; return userExists; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"> <Scripts> <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" /> </Scripts> </asp:ScriptManager> <div> <span>Username:</span> <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox> </div> </form> <script type="text/javascript"><!-- function txtUsername_Keypress(sender, e) { PageMethods.CheckForUsername($get('txtUsername').value, onCheckComplete); } function onCheckComplete(result) { $get('txtUsername').style.backgroundColor = (result) ? '#ffffff' : '#ff0000'; } //--> </script> <script type="text/xml-script"> <page xmlns="http://schemas.microsoft.com/xml-script/2005" xmlns:cc="AtlasExamples"> <components> <textBox id="txtUsername"> <behaviors> <cc:keyUpBehavior keyUp="txtUsername_Keypress" /> </behaviors> </textBox> </components> </page> </script> <script type="text/javascript"> // A behavior to handle the keyup event. Type.registerNamespace('AtlasExamples'); AtlasExamples.KeyUpBehavior = function(element) { AtlasExamples.KeyUpBehavior.initializeBase(this, [element]); } AtlasExamples.KeyUpBehavior.prototype = { // Initialize / Dispose. initialize : function() { AtlasExamples.KeyUpBehavior.callBaseMethod(this, 'initialize'); $addHandlers(this.get_element(), {'keyup':this._onKeyUp}, this); }, dispose : function() { $clearHandlers(this.get_element()); AtlasExamples.KeyUpBehavior.callBaseMethod(this, 'dispose'); }, // Event Handler. _onKeyUp : function(evt) { this._raiseEvent('keyUp', Sys.EventArgs.Empty); }, // Event add_keyUp : function(handler) { this.get_events().addHandler('keyUp', handler); }, remove_keyUp : function(handler) { this.get_events().removeHandler('keyUp', handler); }, _raiseEvent : function(eventName, eventArgs) { var handler = this.get_events().getHandler(eventName); if (handler) { if (!eventArgs) { eventArgs = Sys.EventArgs.Empty; } handler(this, eventArgs); } } } // Descriptor. AtlasExamples.KeyUpBehavior.descriptor = { events: [{name: 'keyUp'}] } AtlasExamples.KeyUpBehavior.registerClass('AtlasExamples.KeyUpBehavior', Sys.UI.Behavior); </script></body></html>

Saturday, March 24, 2012

CascadingDropDown send to database

Hello, hi have 3 cascadingdropdown..

Every thibk works fine but when i click in the button to save the form( or another postback) i cant pick the selected values..

For data returned form the database i do:

AtlasControlToolkit.CascadingDropDownProperties propDist = cascDrpDist.GetTargetProperties(DropDownDist);

propDist.SelectedValue = dt.Rows[0].Table.Rows[0].ItemArray[15].ToString();

AtlasControlToolkit.CascadingDropDownProperties propConc = cascDrpDist.GetTargetProperties(DropDownConc);

propConc.SelectedValue = dt.Rows[0].Table.Rows[0].ItemArray[14].ToString();

AtlasControlToolkit.CascadingDropDownProperties propFreg = cascDrpDist.GetTargetProperties(DropDownFreg);

propFreg.SelectedValue = dt.Rows[0].Table.Rows[0].ItemArray[13].ToString();

to save values for the postbacks

hfCDISTRITO.Text = cascDrpDist.TargetProperties[0].SelectedValue;

hfCCONCELHO.Text = cascDrpDist.TargetProperties[1].SelectedValue;

hfCFREGUESIA.Text = cascDrpDist.TargetProperties[2].SelectedValue;

but if im inserting a new data how can i do so pick the selectedvalues?

Thanks

MArcos ALves

but if im inserting a new data how can i do so pick the selectedvalues?

sorry i want to say:

but if im inserting a new data how can i pick the selectedvalues?

Please help!! im trying this about 3 weeks!!!!Tongue Tied[:'(]

Thanks a lot!


I'm afraid I don't understand the scenario. Could you please describe it a little more?

CascadingDropDown Selects Wrong Item on PostBack

I have a page where the cascadingdropdown is selecting the wrong item in the list on postback. I can verify that the JavaScript created by the AJAX controls says to select item "5::Description Here" yet item 4 gets selected when the page loads after post back. So you select the parent value, then the child, then click a button that does a postback (in this case a search) and when the two drop downs load the first one is selected correctly and the 2nd one, the cascading drop down, has selected the item above the correct item. If I continue to submit the form over and over the selected item just keeps moving up one spot. I attemted to remove any appended items, in my case one that says "-- Select --", as well as the prompttext as it appears to be an "index" issue, but that didn't solve the problem. I have the exact same dropdown fields on another form where they work just fine on postback. I don't want to post the whole page but here are the dropdowns in question. OfficeLocation is the parent and RateSchedule is the child.

<asp:DropDownListID="drpOfficeLocation"runat="server"AppendDataBoundItems="True"DataSourceID="srcOfficeLocations"DataTextField="Value"DataValueField="ID"Width="150px"EnableViewState="True">

<asp:ListItemValue="">-- Select --</asp:ListItem>

</asp:DropDownList>

<asp:DropDownListID="drpRateSchedule"runat="server"AppendDataBoundItems="True"

DataTextField="Value"DataValueField="ID"EnableViewState="False">

</asp:DropDownList>

<cc1:cascadingdropdownid="ccRates"runat="server"category="Location"

loadingtext="Loading Rates..."parentcontrolid="drpOfficeLocation"

servicemethod="GetRateResults"servicepath="JobAJAX.asmx"targetcontrolid="drpRateSchedule"></cc1:cascadingdropdown>

You simply won't believe what I found to be the problem. My controls are in a table that has style="display:none;" and you click an image to show the table. Removing this "display:none" from the table allowed the JS to select the correct item in the dropdown. I added it back and it selected the wrong one again. I can't make any sense of this but that's the problem.