Showing posts with label second. Show all posts
Showing posts with label second. Show all posts

Monday, March 26, 2012

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

Catching drop event in atlas drag and drop

Hi I want to drag a GridView cell and drop it on another GridView and adding a new row in second gridview based on the dragged element name. Is there any method by which I can capture the drop event .Have you tried using theReorderList Control?

Thanks Shepherd. But I want to use drag and drop between two GridView's. ReorderList does not work properly for this purpose. Moreover I tried to use ReorderList with DataSource and it gives me error while reordering. Can u help me regarding this. And I want to execute a Insert command on drop event.

Thanks.


@.Kanwar,

To my knowledge this is not supported yet. I've read requests for this functionality on the AJAX Control Toolkit Codeplex site, but I don't know of any official plans to add it. I assume that it is possible, and that you could build it yourself if you have time...you might also look into some third party controls like Telerik or Infragistics. I don't know if they have controls like this, but they are usually a little ahead of the curve feature-wise. I hope this is helpful.


Best Regards...


Thanks. I am trying to build Ajax template for this.
Best of luck to you.

CascadingDropDowns Not Enabling

I'm just trying to get simple cascading drop down functionalityworking, and I'm having some issues with the second drop down gettingenabled once a selection has been made in the first drop down. I candebug and step through correctly, and everything seems like it shouldbe working, it's just that the control is never enabled.

I've checked this thread (http://forums.asp.net/thread/1278728.aspx), because it seemed similiar, and I've already set enabledEventValidation to false for the page. What am I missing?

Here what I've got:

<asp:DropDownList ID="dropdownlist" runat="server" />
<asp:DropDownList ID="dropdownlist1" runat="server" /
<atlasToolkit:CascadingDropDown ID="CascadingDropDowns" runat="server">
<atlasToolkit:CascadingDropDownPropertiesTargetControlID="dropdownlist" Category="Make" PromptText="Pleaseselect a value" ServicePath="dropdown.asmx" ServiceMethod="GetValues"/>
<atlasToolkit:CascadingDropDownPropertiesTargetControlID="dropdownlist1" ParentControlID="dropdownlist"Category="Model" PromptText="Please select a make" ServicePath="dropdown.asmx" ServiceMethod="GetValues" />
</atlasToolkit:CascadingDropDown
And then, my Web Service:

<%@dotnet.itags.org. WebService Language="VB" Class="dropdown" %
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://k299/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class dropdown
Inherits System.Web.Services.WebService

Public Function dropdown()
Return Nothing
End Function

<WebMethod()> _
Public Function GetValues(ByVal knownCategoryValues As String, ByValcategory As String) As AtlasControlToolkit.CascadingDropDownNameValue()
Dim cddvArray(1) As AtlasControlToolkit.CascadingDropDownNameValue
Dim strDisplay As String = ""
If category = "Make" Then
strDisplay = "Michigan"
Else
strDisplay = "Missouri"
End If
Dim cddv1 As New AtlasControlToolkit.CascadingDropDownNameValue(strDisplay, "MO")
cddvArray(0) = cddv1
Return cddvArray
End Function

End Class

You're creating a 2-element array and filling in only one of the two elements, leaving the other empty. Change the first line of GetValues to the following and your sample works fine for me:

Dim cddvArray(0) As AtlasControlToolkit.CascadingDropDownNameValue


And to think, I was pulling my hair out on something that simple. I knew I should have gotten more sleep :)

Thanks!

Saturday, March 24, 2012

CascadingDropDownList and a MySQL database

How to use CascadingDropDownLists bound to a MySQL-database? I want a parent DDList with items selected from one table and a second DDlist with items selected from another table based on the value selected in the first one. But how to write the asmx-file?

Hi,

First, you can refer to this documentation for how to use it with a database. http://ajax.asp.net/ajaxtoolkit/Walkthrough/CCDWithDB.aspx

Then, as far as I know, MySql provides db driver for .net which can be used in a similar way as the build-in ADO.NET does. You can download it from their website and try to implement it according to the above documentation.

Hope this helps.

CascadingDropDown: How to register OnChange event on client?

Hello,

I have a WebForm with three CascadingDropDown. First is the parent of second list and second is the parent of the third list. And third list has a AutoPostBack feature to populate a GridView in an UpdatePanel on the page. My challenge is clear UpdatePanel content when user change first or second lists value.

So how can I register to onChange something like event of the list on client script? Then I can use $get("UpdatePanelClientId").innerHTML="".


Regards.

Hi,

You may use the following code.

<asp:DropDownList ID="DropDownList1" runat="server" Width="170"onchange="$get('ctl00_SampleContent_UpdatePanel1').innerHTML='';"/>

You can try it on the sample website's CascadingDropDown.aspx page.

Hope this helps.

Wednesday, March 21, 2012

CascadingDropDown problem with the v1.0 version

Hi all,

in one of my pages, i have two dropdowns: one for listing countries and the second for listing the states/provinces of the country selected in the first one dropdown.

When i was using the AJAX Release candidate version, I used the cascadingdropdown without problem. But when i installed the v1.0, the cascadingdropdown stop updating the second dropdown, as used to. Is there someone who can tell me what i am doing wrong?

Part of my code in the aspx file:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel id="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>

<TABLE style="WIDTH: 100%; TEXT-ALIGN: left">
<TBODY> <TR>
<TD style="WIDTH: 328px; TEXT-ALIGN: left">
<asp:DropDownList id="CountryDropDownList" tabIndex=12 runat="server" Width="204px" AutoPostBack="True" DataTextField="Name" DataValueField="Id"></asp:DropDownList>
</TD>

<TD style="WIDTH: 328px; HEIGHT: 24px; TEXT-ALIGN: left">
<asp:DropDownList id="ProvinceDropDownList" tabIndex=12 runat="server" Width="204px" DataTextField="Name" DataValueField="Id"></asp:DropDownList>
</TD>
</TBODY>
</TABLE>

<cc1:CascadingDropDown id="CascadingDropDown1" runat="server" TargetControlID="CountryDropDownList" Category="Country" ServicePath="CustomerSignUp.aspx" ServiceMethod="GetAllCountries" PromptText="<%$ Resources:Messages, SelectCountry %>" LoadingText="<%$ Resources:Messages, Loading %>"></cc1:CascadingDropDown>

<cc1:CascadingDropDown id="CascadingDropDown2" runat="server" TargetControlID="ProvinceDropDownList" Category="Province" ServicePath="CustomerSignUp.aspx" ServiceMethod="GetCountryProvinces" PromptText="<%$ Resources:Messages, SelectProvince %>" LoadingText="<%$ Resources:Messages, Loading %>" ParentControlID="CountryDropDownList"></cc1:CascadingDropDown>

</ContentTemplate>
</asp:UpdatePanel>

</asp:Content>

Methods in the aspx.cs file:

[WebMethod]
public static CascadingDropDownNameValue[] GetAllCountries(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
ICollection<Country> countries = KinocastFacade.Instance.GetAllCountries();
foreach (Country country in countries)
{
values.Add(new CascadingDropDownNameValue(
Resources.Messages.ResourceManager.GetString(country.Name), country.Id.ToString()));
}

return values.ToArray();

}

[WebMethod]
public static CascadingDropDownNameValue[] GetCountryProvinces(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(
knownCategoryValues);
int countryId;

/*Verifica se a chave country está no StringDictionary e se é possivel
*fazer o parse do seu valor para inteiro. Se possivel coloca o valor
*em countryId*/
if (!kv.ContainsKey("Country") ||
!Int32.TryParse(kv["Country"], out countryId))
{
return null;
}

List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
ICollection<Province> provinces = KinocastFacade.Instance.GetCountryProvinces(countryId);
foreach (Province province in provinces)
{
values.Add(new CascadingDropDownNameValue(
Resources.Messages.ResourceManager.GetString(province.Name), province.Id.ToString()));
}

return values.ToArray();
}

Thanks a lot for any help,

Rodrigo

Anyway,

I've just resolved my problem re-creating the project, including all my files and modules again. And at the end, i include the AjaxControlToolkit.dll (version 1.0.10301.0) and the cascadingdropdown problem disapeared.

Maybe, it had happened because the VS saves some olds DLLs in a limbo place :p ...... I dont know...

Cheers.


CascadingDropDown options is null or not an object

I have a couple of dropdown CascadingDropDown and the user is required to select an option from the first and then the second, and then click add. However, if they press add to fast, I get the error "'options' is null or not an object"

It's as if the the second dropdown is not full before the event is posted?!?!? Anyone know how I can prevent this?

Hi Poidda,

Based on my experience, to resolve this kind of issue we should make sure whether the problem is occurred on the client side or on the server side. Based on your description, I think your problem is likely occurred on the server side.

If it is a client issue, we suggest that you should keep the Button to be disabled until the last essential CascadingDropDown is selected. For example:

function pageLoad(){
$find("myCDEState").add_selectionChanged(onCCDSelected)
}
function onCCDSelected(){
//your other javascript code here.

$get("<%=Button.ClientID%>").disabled = false;
}

Otherwise , you should do some checking work on the server side. If it's null, return to the orignal page.

Best regards,

Jonathan

CascadingDropDown is there any way not to show PromptText

I'm using CascadingDropDown and I can't figure out how to get rid of first item (PromptText) in dropdown. I know that my second dropdown always contains at least one item, so I don't want to show PromtText at all and I want to select first item by default. I tried not to use PromptText in CascadingDropDown, but DropDown is always disabled in this case. Is there any way to do what I want?

See work item8672. It discusses not having to require PromptText.