Showing posts with label existing. Show all posts
Showing posts with label existing. Show all posts

Wednesday, March 21, 2012

CalendarExtender RegisterCssReferences Problem

I have an issue when using the CalendarExtender control on an existing page. I'm pretty sure I know why it's happening, I just don't know how to fix it

My aspx page has the <head runat=server> which is required by the script manager to insert what I assume is the CSS references required by the calendar extender control.

The problem is, I get an exception stating:

The Controls collection cannot be modified because the control contains code blocks

We have javascript sitting in the head tag which uses class references to variables that point to aspx page names for example, so we don't have hardcoded page names all over the place. We also have an older implementation of "skinning" where the stylesheet is linked dynamically from a cookie variable, this is where the <%= code blocks are coming from and can't be removed.

Is there a solution to this? I understand the error but find it odd that code blocks are completely blocked in the head tag now

bump...... nobody?

I can't be the only one using code blocks within the <head> tag lol


Hi,

Can you provide a simple sample to illustrate the problem?


Sure, here's really simplified version but it demonstrates the error:

Default2.aspx

<%@.PageLanguage="VB"AutoEventWireup="false"CodeFile="Default2.aspx.vb"Inherits="Default2" %>

<!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>Untitled Page</title>

<scriptlanguage="javascript">

alert('<%=Default2.SomeVariable %>');

</script>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

</div>

<br/>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<ajaxToolkit:CalendarExtenderID="CalendarExtender1"runat="server"TargetControlID="TextBox1">

</ajaxToolkit:CalendarExtender>

</form>

</body>

</html>

In the code behind:

PublicShared SomeVariableAsString ="Hello"


I can see it now.

This is caused by how the Extender works internally. When an Extender is about to be rendered, it examine what css files are required and added it dynamically. So the exception is thrown.

To solve it, please don't use code block in html source directly. You may register it dynamically withRegisterClientScriptBlock method in code behind.


Raymond Wen - MSFT:

I can see it now.

This is caused by how the Extender works internally. When an Extender is about to be rendered, it examine what css files are required and added it dynamically. So the exception is thrown.

To solve it, please don't use code block in html source directly. You may register it dynamically withRegisterClientScriptBlock method in code behind.

Don't use code blocks? Put all my javascript in the code-behind?

Sorry but that's just ludicrous, there has to be another solution? I don't understand why the extender is not able to write a <link> tag in the head section just because there are code blocks present


Asp.net doesn't allow a container's control to be moved when the contaner has code blocks, this may not work reliably.

Another solution is you may move the code block out of the Header, and place it into the Form.

CalendarExtender Position

I am trying to use the CalendarExtender Control in my existing VB.net web application .

Downloaded the latest version of Ajax toolkit and included in the project.

I am using the control inside a Table as below..

My page is too long to fit in a screen. so this date field is at the bottom of the page. So if i scroll the page and selects this calender control,

the postion is lost. popup shows somewhere else. Also this control goes under the ListBoxes which is already there in the page.

What should i do to make the popup calender appear on the relative postion of the TargetControl and on top of other controls ?

In the documentation it says popupup should appear with the targetcontrol ..

<TD>

<asp:textboxid="_dt"runat="server"cssclass="data"columns="16"maxlength="16"></asp:textbox>

<asp:labelid="Label70"runat="server"cssclass="label3"text="(dd-mon-yyyy hhmm)"></asp:label>

<asp:ImageButtonid="btn_dt"Runat="server"ImageUrl="calendar.jpg"CausesValidation=false></asp:ImageButton>

<ajaxToolkit:CalendarExtenderID="calendarButtonExtender"runat="server"TargetControlID="_dt"

PopupButtonID="btn_dt"Format="dd-MMM-yyyy hhmm"/>

</TD>

THanks

-Roopa

Hi Roopa1,

roopa1:

Also this control goes under the ListBoxes which is already there in the page.

To resolve this , you should reference to thez-index.

roopa1:

Showing position issue.

I have tested it with a your code and add blank <tr> above the CalendarExtender. And it works fine on IE7 and Firefox. So would you please provide a simple sample here?

Hope this help.

Best regards,

Jonathan