Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Wednesday, March 28, 2012

Dynamic generated Controls doesnt work, javascript error

I have an ajax enabled control which has a Dropdownlist that changes the Textbox when index gets changed. It is working fine if I use an ASPX page that contains the control in design time.

However, when I dynamically add this control to the ASPX in run time, I got an error when the Dropdownlist is triggered:

Javascript error: System.InvalidOperationException: A control with ID 'myDropDownList' could not be found for the trigger in UpdatePanel..etc..

What should I do? Please help..

There's a good chance that if you look at your page source you'll find that the dynamic control does not have a clientside Id of 'myDropDownList'. It'll probably have something more complex like ct100_myDropDownList or something.

Two possible fixes: 1) wire up your javascript on something other than the id (e.g. iterate over getElementsByTagName), or 2) render the control's ClientID inside a script tag on the page like: var ddl = '<%= myDropDownList.ClientID %>'

HOpe that helps.

dynamic AnimationExtender

I have a list of users in a database and I want to return the list of users to an aspx page with a user icon. I then want to have an ajaxToolkit:AnimationExtender attached to each icon. I have the ajaxToolkit:AnimationExtender working for a single image on a page with all of the script code in the markup. How do I at runtime set a ajaxToolkit:AnimationExtender for each icon.

Thanks

OK,

I have been playing with the toolkit sample code to try and make it OO to some degree. Here is what I have:

3 functions

1 to make the flyout panel,1 to make the onclick open animation and 1 to make the onclick close animation.

I can make the the first to work but I am having trouble with the last one becuase the sample code uses a asp:linkbutton to close the animation. When I try and build it from code/html it is not being converted into a control and the close animation can't find it's targetcontrol id.

here is the flyout panel:

publicstring BuildAnimationPopup(string inPopUpHTML ,outstring flyout,outstring info,outstring btnCloseParent,outstring close)

{

System.Text.StringBuilder sb =new System.Text.StringBuilder();

flyout ="flyout" +DateTime.Now.Millisecond.ToString(); //just to make it unique

info ="info" +DateTime.Now.Millisecond.ToString(); //just to make it unique

btnCloseParent ="btnCloseParent" +DateTime.Now.Millisecond.ToString(); //just to make it unique

close ="btnClose" +DateTime.Now.Millisecond.ToString(); //just to make it unique

//<!-- "Wire frame" div used to transition from the button to the info panel -->

sb.Append("<div id='"+ flyout +"' style='display: none; overflow: hidden; z-index: 2; background-color: #FFFFFF; border: solid 1px #D0D0D0;'></div>");

//<!-- Info panel to be displayed as a flyout when the button is clicked -->

sb.Append("<div id='"+info+"' style='display: none; ; z-index: 2; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); font-size: 12px; border: solid 1px #CCCCCC; background-color: #FFFFFF; padding: 5px;'>");

sb.Append("<div id='"+btnCloseParent+"' style='float: right; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);'>");

//sb.Append("<asp:LinkButton id='"+close +"' runat='server' OnClientClick='return false;' Text='X' ToolTip='Close' Style='background-color: #666666; color: #FFFFFF; text-align: center; font-weight: bold; text-decoration: none; border: outset thin #FFFFFF; padding: 5px;' />");

sb.Append("<a onclick='return false;' runat='server' id='"+close+"' title='Close' style='background-color: #666666; color: #FFFFFF; text-align: center; font-weight: bold; text-decoration: none; border: outset thin #FFFFFF; padding: 5px;'>X</a>");

sb.Append("</div>");

sb.Append("<div>");

sb.Append(inPopUpHTML);

sb.Append("</div>");

sb.Append("</div>");

return sb.ToString();

}

As you can see I have tried it both ways, using an asp:linkbutton and a plain old <a> with the runat=server tag but the Ajax control still can't find it.

Any thoughts?

Saturday, March 24, 2012

DropShadowExtender

I have a masterpage with the code below.

I have a Default.aspx page that uses the masterpage.

When Rounded is set to false then I get a panel with a shadow. If i changes Rounded to true, then I get two small areas (one white and one black). What am I doing wrong.

Best regards

S?ren Agerbo Jensen.

-------

MasterPage.master:

<%@dotnet.itags.org.MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs"Inherits="MasterPage" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>FraIdeTilFaktura.dk</title>

</

head>

<

bodyalign="center"style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#EEEEEE', startColorstr='#555555', gradientType='0'); padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px;"><formid="form1"runat="server"style="text-align: center;"><div><tableborder="0"cellpadding="0"cellspacing="0"style="height: 600px; width: 80%;"><tr><tdstyle="width: 100%; height: 50px;"></td></tr><tr><tdid="tekst"style="width: 100%; height: 400px;"><asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager> <ajaxToolkit:DropShadowExtenderRounded="false"ID="DropShadowExtender1"runat="server"TargetControlID="Panel1"Radius="2"TrackPosition="true"Width="5"></ajaxToolkit:DropShadowExtender><asp:PanelID="Panel1"runat="server"Height="100%"Width="100%"BackColor="White"ScrollBars="Auto"><

<

asp:ContentPlaceHolderID="ContentPlaceHolder1"runat="server"></asp:ContentPlaceHolder></asp:Panel></td></tr><tr><tdstyle="width: 100%; height: 50px;"></td></tr></table></div></form>

</

body>

<

scripttype="text/javascript">

document.getElementById(

"tekst").style.height=screen.height-300;

</

script>

</

html>

Sorry for the trouble - pleaseopen a work item to report and track this issue. Thank you!

Dropdownlist not working within an UpdatePanel

I have a MasterPage with a ScriptManager EnablePartialRendering set to true.

On my AddDeceseadInfo.aspx page I have multipe textboxes and a dropdownlist all wrapped in a UpdatePanel. Also on the AddDeceasedInfo.aspx page (content) I have a ProxyScriptManager.

When I pick a value from the Dropdownlist the value is always "".

When I set AutoPostBack to true my ValidationControl fires and tells me the dropdownlist can not be empty which at that point it is.

When I set the AutoPostBack to false once a pick a value from the dropdownlist all the data in the dropdownlist disappears.

Can somebody help out a AJAX newbie............Cheers!

protectedvoid Page_Load(object sender,EventArgs e)

{

TextBoxFirstName.Focus();

if (!IsPostBack)

{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

}

}

protectedvoid ButtonReset_Click(object sender,EventArgs e)

{

Utility.WebUtility.ClearAllTextBoxes(this);

}

protectedvoid ButtonSubmit_Click(object sender,EventArgs e)

{

if (Page.IsValid)

{

string firstName =HttpUtility.HtmlEncode(TextBoxFirstName.Text).Trim();

string middleName =HttpUtility.HtmlEncode(TextBoxMiddleName.Text).Trim();

string lastName =HttpUtility.HtmlEncode(TextBoxLastName.Text).Trim();

string nickName =HttpUtility.HtmlEncode(TextBoxNickName.Text).Trim();

DateTime dateOfBirth =Convert.ToDateTime(HttpUtility.HtmlEncode(TextBoxDateOfBirth.Text).Trim());

DateTime dateOfDeath =Convert.ToDateTime(HttpUtility.HtmlEncode(TextBoxDateOfDeath.Text).Trim());

int causeOfDeathID =Convert.ToInt32(DropDownListCauseOfDeath.SelectedValue);string birthPlace =HttpUtility.HtmlEncode(TextBoxBirthPlace.Text).Trim();

}

else

{

}

}

}

Set AutoPostBack to true and also set CauseValidation property to false


Set the EnableClientScript property to false on your validation control. Validators aren't supported in an UpdatePanel, this may be causing you issues,see Item #4 for more information

-Damien


I guess my post was not clear but the answers posted did not really help. My DropDownList is inside an UpdatePanel.

The ScriptManager is set to enable patial rendering.

AutoPostBack is set to true.

My UpdatePanel has UpdateMode set to Conditional

I populate the DropDownList with values from my database. When the page loads the values are there in the DropDownList. When I go and pick a value the data from the DropDownList disappears. Basically I end up with a empty DropDownList. Values gone................

When I set the AutoPostBack property to false the data stays in the DropDownList after I pick a value but when I hit the submit button the Validation control fires because the DropDownList is all of a sudden empty again.

I am running the latest Versions of ASP.Net Ajax and was under the impress the validator problems have been solved in the latest version. It seems to work on all my other froms that I use the UpdatePanel. The Validator controls and UpdatePanel work nicely together.

There seem to be no examples on the web where somebody has on DropDownList in an UpdatePanel and simple wants to get the value from that DropDownList and the additional TextBoxes once the Submit button is clicked.

I watched some of the ASP.Net videos and there are some Extenders that might be useful but it is too much work. Isn't there a why of making a simple DropDownList work within a UpdatePanel. So I can get the value from it.


How are you binding the list; are you possibly clearing it on the postback? Do you have ViewState enabled for the DropDownList?

Also, I'm using a DropDownList in an UpdatePanel successfully so it does work.

-Damien


Thanks for your reply, here is my Page_Load

protectedvoid Page_Load(object sender,EventArgs e)

{

TextBoxFirstName.Focus();

if (!IsPostBack)

{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

}

}


If I comment if(!Ispostback) out then the form works as it should the only problem is the that the DropDownList gets bound again after I hit the submit button and therefore the the ID returned by the DropDownList is always 1. Somebody it sitting on my brain and I can't figure this out. Any ideas? Thanks, Newbie

protectedvoid Page_Load(object sender,EventArgs e)

{

TextBoxFirstName.Focus();

//if (!IsPostBack)

//{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

//}

}


Just fixed the problem. I overrode the OnInit event like this

protectedoverridevoid OnInit(EventArgs e)

{

base.OnInit(e);

PopulateDropDownList();

}

and added a PopulateDropDownList() method

privatevoid PopulateDropDownList()

{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

}

Set the AutoPostBack to false

EnableViewState to true

UpdatePanel to Conditional

ScriptManager EnablePartialRendering to true

And it is all working now like a charm. DropDownList works in UpdatePanel and so do the validation controls. Thanks Microsoft.....................


Thank you for posting the solution. You just made my day!

Wednesday, March 21, 2012

Dropdownlist doesnt refresh in Updatepanel

Hi all,

I'm just taking my first steps in the altlas world here, so i guess the problem below will be due to myself:

i created an .aspx page containing some dropdowns, and coded the functionality using postbacks. Up until there it all works. Then i tried to refresh one of the dropdowns using Atlas - triggered by another dropdown control.

Now when i change the selected value in the "trigger" control, the code filling the other dropdown is executed but the controls content isn't refreshed when the execution is completed.

Here's the code on the aspx page...

...

<atlas:ScriptManager ID="s" EnablePartialRendering="true" runat="server"></atlas:ScriptManager>

...

SalesCompany:<asp:DropDownList ID="ddlSalesCompany" runat="server" OnSelectedIndexChanged="ddlSalesCompany_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList><br/>
Series:<asp:DropDownList ID="ddlSeries" runat="server" OnSelectedIndexChanged="ddlSeries_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList><br/>
<atlas:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
Model:<asp:DropDownList ID="ddlModel" runat="server" OnSelectedIndexChanged="ddlModel_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList><br/>
</ContentTemplate>
<Triggers>
<atlas:ControlValueTrigger ControlID="ddlSeries" PropertyName="SelectedIndex" />
</Triggers>
</atlas:UpdatePanel>

in my "code behind" page i have:

protected void ddlSeries_SelectedIndexChanged(object sender, EventArgs e)
{
FillModels();
}

private void FillModels()
{
if (ddlSeries.SelectedValue != "0")
{
Proxy.Pricing.Model.ModelService ModelSVC = new Proxy.Pricing.Model.ModelService();
DKSerie dkSerie = new DKSerie(ddlSeries.SelectedValue.ToString());

List<Model> myModels = ModelSVC.GetModels(dkSerie, null);

ddlModel.DataSource = myModels;
ddlModel.DataTextField = "Name";
ddlModel.DataValueField = "OID";
ddlModel.DataBind();

ddlModel.Items.Insert(0, new ListItem("Select a model", "0"));
}
else
{
ddlModel.Items.Clear();
ddlModel.Items.Insert(0, new ListItem("Select a series", "0"));
}
}

Can somebody help me on this one?

Thanks in advance,

Wesley Van den Eede

The thing that triggers the UpdatePanel is the Triggers Collection of the Update Panel. I noticed in your Triggers Collection you have the property of the trigger to be "SelectedIndex" where it probably should be "SelectedIndexChanged" (at least it is in mine).

Mike


Hi Mike,

Thanks for the reply, but...

Isn't that in case i use a ControlEventTrigger instead of a ControlValueTrigger?

I watched Scott's presentation athttp://atlas.asp.net/ and he uses SelectedIndex.

Wesley


Sorry for the double post...

The thing is that, i don't think it is related to the trigger... because when i debug and put a breakpoint on the FillModels() function, the debugger really steps in. It looks like the actual rendering of the control isn't refreshed?

Wesley


Can you monitor the network traffic using Fiddler or Nikhil's browser helper and tell us what you see?

Hi,

Sorry for the late reply (working on another project :))

Today i tried to use fiddler a bit, but then i found out that it doesn't work with IE7?, I'll try to send the fiddler output this afternoon anyway.

On the other hand i did some more investigation and found out that it is probably related to two other controls i use further in the page: Infragistics.WebUI.WebDateChooser.v1.2

When i remove the controls it all works, so i guess it's now a case of making them work together (or replacing the WebDateChooser controls) ... any suggestions?

Kind regards,

Wesley Van den Eede


Yes, we know of a few problems with the Infragistics controls which are quite heavily using JavaScript.

I just updated our datepicker controls to the latest trial version of the netadvantage suite (2006 Vol. 1) ... now it works perfectly...

Thanks for the responses.