Showing posts with label cant. Show all posts
Showing posts with label cant. Show all posts

Wednesday, March 28, 2012

Accordian - How to refer to contained controls in code behind?

Hi,

If i put regular asp.net controls into an accordian pane they are not visible in the code behind file. In other words i cant get mydropdown.selectedvalue if mydropdown is contained in an accordian pane because the compiler will complain that mydropdown doesn't exist? My work around has been to put content into user controls and put the ascx's into the content panes but is this standard practise?

Thanks

Richard

Hi Richard,

Since the AccordionPanes can be databound, they implement theINamingContainer interface and you're unable to access them directly in your code behind. You can work around this withDropDownList list = MyAccordion.FindControl("MyDropDown") as DropDownList;.

Thanks,
Ted

Accessing Controls From JavaScript

What is the syntax for accessing control form javascript? I can't seem to find it anywhere - I thought it was something like

dunction HideOne(n)

{

var ele = Sys($(n))

}

not a lot to go on with what you have provided but...

assuming that "n" in this context is the id of an element you want to "access" or get then you should use "$(n)"
to avoid issues with that statement... in your example you would remove the Sys() part and only have the $(n) part

this all depends on, however, how you are creating your elements. if you are using the xml-script declarative approach then you might be better off using the $object() function.
the $object() function searches the current markup context for the element, then traverses the tree up to the Application level to try to find the element.
this is different than the $() function which is nothing more than a shortcut for "document.getElementById()"

this allows the ATLAS runtime to have (or support) multiple elements with the same "id" without violating the HTML 4.1 specifications stating "an elements id must be unique" which it clearly would be (in the current context)

hope that helps... if not try adding some more of your code so we can get a better understanding of what you are dealing with


That was perfect thanks.

Saturday, March 24, 2012

A simple question: Do webservices work with the beta?

I can't seem to get of my webservice to work. All I get is object undefined. I have javascript that gets triggered on an onblur() event which calls a webservice where the code is in another file. Nothing I do will get it to work. I've tried all the solutions I've found and still errors.

Same goes for cascadingdropdowns. It's like my webservice is invisible. I read the sticky about putting the webservice call in the aspx file and I did that but it still can't be found.

I find that the documentation is limited and what I do find, it seems to be written for experts. So, I guess for now, I have no option but to dump the path I'm on since it appears to me the code isn't ready for beta. Too many issues. Not enough documentation and examples.

Very frustrated!

Hi jax67, can we see the webservice class and the javascript function that calls it? Also the error message that you are getting. Maybe I can help. I used cascadingdropdowns a lot too, it was very frustated at first, but then I figured it out. So, everything is all good now.

Thanks AW - I am so frustrated :( The first file is in a folder called Maint (off of the root) and the webservice asmx file is in the root. The code for the webservice is in app_code.

Here is the code that has the javascript call. The onblur is what calls the javascript and that part works. It's the actual call to the service that fails. I put an alert before the call and the alert is displayed. A javascript error occurs after I dismiss the alert. I do not have the alert code in the following code files.

Thank you for any help you can provide. I really do appreciate it...

Dave

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Amendment.aspx.cs" Inherits="Maint_Amendment" Title="Add A New Contract Amendment"
EnableEventValidation="false" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<ajax:ScriptManager ID="sm" runat="server" EnablePartialRendering="True">
<Services>
<ajax:ServiceReference Path="../ContractService.asmx"/>
</Services>
</ajax:ScriptManager>
<script type="text/javascript" language="javascript">
function AddDates_click()
{
// Get the values necessary to pass to the webservice
var startDate = $get('<%= txtStartDate.ClientID %>').value;

var periodInYears = $get('<%= txtPeriodYears.ClientID %>').value;
if (periodInYears == "") periodInYears = "0";

var periodInMonths = $get('<%= txtPeriodMonths.ClientID %>').value;
if (periodInMonths == "") periodInMonths = "0";

if (startDate != "")
{
// Show the progress and resize the textbox
document.getElementById('calculating').style.display = '';
$get('<%= txtExpirationDate.ClientID %>').style.width = '90%';
// Make the call to the webservice
alert("Before Call...");
var x = ContractService.CalculateExpirationDate(startDate, periodInYears, periodInMonths, OnComplete, OnTimeout);
}

return false;
}
function OnComplete(result)
{
$get('<%= txtExpirationDate.ClientID %>').value = result;
document.getElementById('calculating').style.display = 'none';
$get('<%= txtExpirationDate.ClientID %>').style.width = '98%';
}
function OnTimeout(result)
{
document.getElementById('calculating').style.display = 'none';
$get('<%= txtExpirationDate.ClientID %>').style.width = '98%';
}
</script>
<ajax:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="http://pics.10026.com/?src=../images/spinner.gif" />
</ProgressTemplate>
</ajax:UpdateProgress>
<ajax:UpdatePanel ID="upAmendment" runat="server">
<ContentTemplate>
<table align="center" border="1" bordercolor="#000000" cellpadding="4" style='width: 50%;
border-collapse: collapse">
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label2" runat="server" SkinID="bold" Text="Amendment Num"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtAmendmentNumber" runat="server" MaxLength="10" ReadOnly="True"></asp:TextBox><br />
<asp:TextBox ID="txtContract" runat="server" ReadOnly="True" Visible="False"></asp:TextBox></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="lblStartDate" runat="server" SkinID="bold" Text="Start Date"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtStartDate" runat="server" MaxLength="15" onblur="return AddDates_click()"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtStartDate"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regStartDate" runat="server" ControlToValidate="txtStartDate"
Display="Dynamic" ErrorMessage="Invalid Date Format"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label3" runat="server" SkinID="bold" Text="Period (Years)"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtPeriodYears" runat="server" MaxLength="3" onblur="return AddDates_click()"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngYears" runat="server" ControlToValidate="txtPeriodYears"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="100" MinimumValue="1"
Type="Integer" SetFocusOnError="True"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label4" runat="server" SkinID="bold" Text="Period (Months)"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtPeriodMonths" runat="server" MaxLength="2" onblur="return AddDates_click()"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtPeriodMonths"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="11" MinimumValue="0"
SetFocusOnError="True" Type="Integer"></asp:RangeValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label5" runat="server" SkinID="bold" Text="Expiration Date"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtExpirationDate" TabIndex="-1" runat="server" MaxLength="15"></asp:TextBox>
<span id="calculating" style='display: none;'>
<img src="http://pics.10026.com/?src=../images/spinner.gif" /></span>
</td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label11" runat="server" SkinID="bold" Text="Class"></asp:Label></td>
<td class="alt">
<asp:DropDownList ID="ddlClass" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqClass" runat="server" ControlToValidate="ddlClass"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label12" runat="server" SkinID="bold" Text="Type Of"></asp:Label></td>
<td class="alt">
<asp:DropDownList ID="ddlType" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqType" runat="server" ControlToValidate="ddlType"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label6" runat="server" SkinID="bold" Text="Consideration"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtConsideration" runat="server" MaxLength="10" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngConsideration" runat="server" ControlToValidate="txtConsideration"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="999999999" MinimumValue="0"
SetFocusOnError="True" Type="Double"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label7" runat="server" SkinID="bold" Text="Percent of Credit"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtPercentCredit" runat="server" MaxLength="30" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngPercentCredit" runat="server" ControlToValidate="txtPercentCredit"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="100" MinimumValue="0"
SetFocusOnError="True" Type="Double"></asp:RangeValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label8" runat="server" SkinID="bold" Text="Credit Type"></asp:Label></td>
<td class="alt">
<asp:DropDownList ID="ddlCreditType" runat="server" DataTextField="LOV_ITEM" DataValueField="LOV_VALUE">
</asp:DropDownList></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label9" runat="server" SkinID="bold" Text="Carry Forward (Years)"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtCarryForward" runat="server" MaxLength="2" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngCarryForward" runat="server" ControlToValidate="txtCarryForward"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="100" MinimumValue="0"
SetFocusOnError="True" Type="Integer"></asp:RangeValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label10" runat="server" SkinID="bold" Text="Assignable ?"></asp:Label></td>
<td class="alt">
<asp:RadioButtonList ID="optAssignable" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="lblEffectivityDate" runat="server" SkinID="bold" Text="Effectivity Date"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtEffectivityDate" runat="server" AutoCompleteType="Disabled" MaxLength="15"
onblur="return AddDates_click()"></asp:TextBox>
<asp:RegularExpressionValidator ID="regEffectivityDate" runat="server" ControlToValidate="txtEffectivityDate"
Display="Dynamic" ErrorMessage="Invalid Date Format"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqEffectivityDate" runat="server" ControlToValidate="txtEffectivityDate"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator></td>
</tr>
</table>
<ajaxToolkit:CascadingDropDown ID="cddClass" runat="server" Category="Class" PromptText="Select a Class"
ServicePath="../ContractService.asmx" ServiceMethod="GetClasses" TargetControlID="ddlClass" Enabled="true" />
<ajaxToolkit:CascadingDropDown ID="cddType" runat="server" Category="Type" PromptText="Select a Type"
ServicePath="../ContractService.asmx" ServiceMethod="GetTypes" TargetControlID="ddlType" ParentControlID="ddlClass" Enabled="true" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmPeriodYears" runat="server" TargetControlID="txtPeriodYears" WatermarkCssClass="WaterMark" WatermarkText="Terms in years" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmPeriodMonths" runat="server" TargetControlID="txtPeriodMonths" WatermarkCssClass="WaterMark" WatermarkText="Terms in months" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmStartDate" runat="server" TargetControlID="txtStartDate" WatermarkCssClass="WaterMark" WatermarkText="Contract Start Date" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmConsideration" runat="server" TargetControlID="txtConsideration" WatermarkCssClass="WaterMark" WatermarkText="Amount paid or units mined in consideration" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmPercentCredit" runat="server" TargetControlID="txtPercentCredit" WatermarkCssClass="WaterMark" WatermarkText="% of credit received from payment" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmCarryForward" runat="server" TargetControlID="txtCarryForward" WatermarkText="Period in years credits may be carried forward" WatermarkCssClass="WaterMark" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmEffectivityDate" runat="server" TargetControlID="txtEffectivityDate" WatermarkCssClass="WaterMark" WatermarkText="When does this amendment take affect" />
</ContentTemplate>
</ajax:UpdatePanel>
<asp:Panel runat="server" ID="pnlReasonForEdit" SkinID="reasonforedit">
<br />
<table align="center" border="1" bordercolor="#000000" cellpadding="4" style='width: 50%;
border-collapse: collapse">
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label1" runat="server" SkinID="bold" Text="Reason for Edit"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtReasonForEdit2" runat="server" MaxLength="2000" TextMode="MultiLine"
Rows="2"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqReasonForEdit" runat="server" ControlToValidate="txtReasonForEdit2"
Display="Dynamic" ErrorMessage="A reason must be entered" SetFocusOnError="True"></asp:RequiredFieldValidator></td>
</tr>
</table>
</asp:Panel>
<p align="center">
<asp:Button ID="cmdSave" runat="server" OnClick="cmdSave_Click" Text="Save" />
<asp:Button ID="cmdCancel" runat="server" CausesValidation="False" OnClick="cmdCancel_Click"
Text="Cancel" />
</p
<script type="text/javascript">
var styleToSelect;
function onOk() {
//$get('Paragraph1').className = styleToSelect;
}
</script
<asp:Panel ID="Panel1" runat="server" Style='display: none' Width='65%' SkinID='ReasonHeader'>
Please provide a reason for the edit
<asp:Panel ID="pnlBody" runat="server" SkinID="ReasonBody" Style='margin: 5px;'>
<br />
Enter the reason for editing this Amendment:
<asp:TextBox EnableTheming="false" runat="server" ID="txtReasonForEdit" TextMode="multiLine"
Width="96%" Rows="5"></asp:TextBox>
<br />
<br />
<center>
<asp:Button ID="OkButton" runat="server" Text="OK"></asp:Button>
<asp:Button ID="CancelButton" runat="server" Text="Cancel"></asp:Button>
</center>
<br />
</asp:Panel>
</asp:Panel>
</asp:Content>

Here is the Webservice file:

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Web.Script.Services;

/// <summary>
/// Summary description for ContractService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[Microsoft.Web.Script.Services.ScriptService()]
public class ContractService : System.Web.Services.WebService {

public ContractService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string GetNextContractSequence(string contract)
{
// ---------------------------
// Author: dzangger
// Company: Huber
// Date: 8/4/2006
// Time: 12:06
// Procedure Name: GetNextContractSequence
// Purpose: Get the next available sequence number for contract
// Parameters:
// - contract (string)() :
// ---------------------------
return contract.ToUpper() + CMSDB.GetNextContractSequence(contract.ToUpper());
}

[WebMethod]
public string DoesContractExist(string contract)
{
bool b = CMSDB.DoesContractExist(contract);

if (b)
return "~" + contract.ToUpper();
else
return contract.ToUpper();
}

[WebMethod]
public string GetIndexValue(string index, string beginDate, string endDate)
{
try
{
DateTime d = Convert.ToDateTime(beginDate);
d = Convert.ToDateTime(endDate);
}
catch (Exception)
{
return "";
}

return CMSDB.GetIndexValueFromDateRange(index, beginDate, endDate);
}

[WebMethod]
public string CalculateExpirationDate(string startDate, string years, string months)
{
// ---------------------------
// Author: dzangger
// Company: Huber
// Date: 8/3/2006
// Time: 13:21
// Procedure Name: CalculateExpirationDate
// Purpose: Adds a number of years and months to a given date
// Parameters:
// - startDate (string)() :
// - years (string)() :
// - months (string)() :
// ---------------------------
try
{
int iYears = 0, iMonths = 0;

try
{
iYears = Convert.ToInt16(years);
}
catch (Exception)
{
iYears = 0;
}

try
{
iMonths = Convert.ToInt16(months);
}
catch (Exception)
{
iMonths = 0;
}

DateTime date = Convert.ToDateTime(startDate);

if (iYears > 0)
date = date.AddYears(iYears);

if (iMonths > 0)
date = date.AddMonths(iMonths);

return date.ToShortDateString();
}
catch (Exception)
{
return "";
}
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetIndexTypes(string knownCategoryValues, string category)
{
// ---------------------------
// Author: david.zangger
// Company: Huber
// Date: 10/13/2006
// Time: 07:27
// Procedure Name: GetIndexTypes
// Purpose: Gets the indexes and their types
// Parameters:
// - knownCategoryValues (string)() :
// - category (string)() :
// ---------------------------
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

IDataReader reader = CMSDB.GetIndexesAndIndexTypes();

while (reader.Read())
{
string classId = reader[0].ToString();
string index = reader[1].ToString();
values.Add(new CascadingDropDownNameValue(classId, index));
}

reader.Close();

return values.ToArray();
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetIndexSeries(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

StringDictionary sd = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

if (sd.ContainsKey("Index"))
{
IDataReader reader = CMSDB.GetSeriesIds(sd["Index"].ToString());

while (reader.Read())
{
string series = reader[0].ToString();
values.Add(new CascadingDropDownNameValue(series, series));
}

reader.Close();

return values.ToArray();
}
else
return null;
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetClasses(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

IDataReader reader = CMSDB.GetContractClasses();

while (reader.Read())
{
string classId = reader[0].ToString();
values.Add(new CascadingDropDownNameValue(classId, classId));
}

reader.Close();

return values.ToArray();
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetTypes(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

StringDictionary sd = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

if (sd.ContainsKey("Class"))
{
IDataReader reader = CMSDB.GetContractTypes(sd["Class"].ToString());

while (reader.Read())
{
string classId = reader[1].ToString();
string desc = reader[0].ToString();
values.Add(new CascadingDropDownNameValue(desc, classId));
}

reader.Close();

return values.ToArray();
}
else
return null;
}
}

I seem to have it working. I created a new website (using the CTP version) and then used the web.config from that project. I migrated my appsettings and an Oracle assembly and then moved my webservice in the folder where the files calling it resides. For now, I'm going to leave it as it is.

Thanks AW for your assistance!

dave

Wednesday, March 21, 2012

A quick redirect/ whole page refresh question

Hello everyone,

I'm new to the ajax framework and I have a quick question/problem This could be a simple issue, but i can't quite seem to figure this one out..

I'm using ajax to update a shopping cart located in <div id=cart>

So far so good :) no problems!!!

Without ajax the logic is setup like, if you have entered a incorrect item number or partial #, then you are redirected to the search page

But how can I get the whole page to redirect to the search page instead of just the <div> tag when someone enters an incorrect item number after the <div> has been ajax'd.

BTW i'm having to do some touch up work in ASP classic :(

any direction is greatly appreciated!!! :D

Thx in adv

how are you trying to do this now. As far as i know doing Response.Redirect("entereurlhere"); will send the whole page to a new location.


Let's if i can accurately explain..without having to strip and prep code(4000 lines...lol) and confusing everyone including myself...

we have...

------------------
main page

List Item 1
List Item 2
List Item 3 -------
^--onclick updates --> | shopping cart |
-------
------------------

The shopping cart logic also have an option to manually enter a item#
if an invalid# is entered, then it'll response.redirect to the search page
the problem is it only refreshes the <div> and not the whole page

so we have...

------------------
main page

List Item 1
List Item 2
List Item 3
-----------
| Angry search pageAngry |
------------
------------------

instead of :

------------------
search page

Cool

------------------


I'm slightly confused.

If you have your basket in an update panel and your "add to basket button" is wired to a Subroutine which is then redirecting to a differnent page using response.redirect then I'm not sure how the search page would load inside your basket, unless your basket is inside an IFRAME or something like that. I think we would need to see your code, or a simplified version of it.