Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Wednesday, March 28, 2012

extenders arent working at all

Hi. I have installed libarary and control toolkit, and I have the following code:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TaskCenter.WebForm1" EnableEventValidation="true" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI" TagPrefix="aj" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI.Controls" TagPrefix="aj" %><!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 runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <aj:ScriptManager ID="sm" EnablePartialRendering="True" runat="Server" /> <asp:Label ID="test" runat="Server">test</asp:Label> <asp:Panel ID="panel1" runat="server" Enabled="true">testtttt</asp:Panel><ajax:DropDownExtender runat="server" ID="DDE" TargetControlID="test" DropDownControlID="panel1" OnResolveControlID="DDE_ResolveControlID" /> </div> </form></body></html>

Problem is, it doesn't work. The app builds without any problem, and when I open the page i see two text labels - test and testtt, no extender, no dropdown.

How do I fix it?

Look in the web.config for the SampleWebsite. Make sure you have the sections under httpHandlers and httpModules in your web.config.

Extended controls may not be registered before Pre-Render

hi all,

i get the following error message when trying to load a usercontrol containing a modalpopupextender:
"extended controls may not be registered before pre-render"

no line specified, no more info about what's wrong, and almost everything is done with click 'n' drag in design mode (vwd 2005).

default.aspx and its codebehind:http://www.aspsidan.se/code/default.asp?c=9359

editcontent.ascx and its codebehind:http://www.aspsidan.se/code/default.asp?c=9361

the error message:http://www.aspsidan.se/code/default.asp?c=9360

editcontent.ascx is, as you can see, within a loginview, and it's not until i log on that i get the problem. i guess this error has something to do with the page life cycle, but i have no clue of how to get around it...

(i posted the code already in another forum, so i refer to those pages. i hope they're available even if you're not logged on. i've tried when i was offline and it worked, so it shouldn't be a problem...)

Hi lycken,

It is a common issue. You should add base.OnPreRender at the beginning ofvoid OnPreRender(EventArgs e){};

For more , pleaseread this. If it doesn't work, please feel free to let me know.

Best regards,

Jonathan


hi jonathan,

thanks a lot for the reply! it really does save my day that there is a solution to this.

however, neither your answer nor the article you linked me to helped me all the way. i understand i have to call the base.OnPreRender routine, but i can't figure out where in my code to put the call. i am coding in vb, so if you could explain it with vb examples instead of c# it would help me ;)

thanks again for your help!

-tomas


Hi Lycken,

Would you please give us a tiny and workable repro? So you can benefit from it directly. Thanks for your understanding.

Best regards,

Jonathan


hi again jonathan,

i provided all my source code in the first post - unless the links are not working. it's pasted below anyway - excuse the lenghtyness... and again - thanks for helping out!

the db is designed as follows:

Texts
******
TextID | int (identifier, primary key)
TextName | varchar(15)
Text | varchar(max)

Default.aspx

1<%@. Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="Default.aspx.vb"Inherits="_Default" title="Untitled Page" Theme="SMK" Trace="true" %>
2<%@. RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
3<%@. Register TagPrefix="list" TagName="Concerts" src="~/konsertprogram/Concerts.ascx" %>
4<%@. Register TagPrefix="ucl" TagName="EditContent" src="~/admin/EditContent.ascx" %>
5
6<asp:Content ID="Content1" ContentPlaceHolderID="Left" Runat="Server">
7 <asp:Image ID="LeftPaneImage" runat="server" ImageUrl="~/image/bredvid_konserter.jpg" />
8</asp:Content>
9<asp:Content ID="Content2" ContentPlaceHolderID="Content" Runat="Server">
10 <asp:Label ID="TextLabel" runat="server" />
11 <div style="text-align:right; width:100%;">
12 <asp:LoginView ID="LoginView1" runat="server">
13 <RoleGroups>
14 <asp:RoleGroup Roles="Admin">
15 <ContentTemplate>
16 <ucl:EditContent ID="EditContentUserControl" runat="server" TextToEdit="hem" />
17 </ContentTemplate>
18 </asp:RoleGroup>
19 </RoleGroups>
20 </asp:LoginView>
21 </div>
22
23 <div class="row">
24 <div style="float:left;">
25 <h1>N?sta konsert:</h1>
26 <list:Concerts ID="Concerts" runat="server" ItemsToShow="1" />
27 </div>
28
29 <div style="float:left;">
30 <h1>En till ruta</h1>
31 <p>med lite info</p>
32 </div>
33 </div>
34
35</asp:Content>

Default.aspx.vb

1Imports System.Configuration
2Imports System.Data.SqlClient
3Imports System.Data.SqlDbType
4Imports ErrorHandling
5
6PartialClass _Default
7Inherits System.Web.UI.Page
8
9Dim objConnAs New SqlConnection(ConfigurationManager.ConnectionStrings("SMK").ConnectionString)
10
11Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load
12Dim objCmdAs New SqlCommand("SELECT [Text] FROM [Texts] WHERE [TextName] ='hem'", objConn)
13
14Try
15 objConn.Open()
16 TextLabel.Text = StringFunctions.FormatText(objCmd.ExecuteScalar)
17Catch exAs Exception
18 Err.Log(ex)
19Finally
20 If objConn IsNotNothing Then objConn.Close()
21End Try
22 End Sub
23End Class

EditContent.ascx

1<%@. Control Language="VB" AutoEventWireup="false" CodeFile="EditContent.ascx.vb"Inherits="admin_EditContent" %>
2<%@. RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
3<asp:ScriptManager ID="ScriptManager1" runat="server">
4</asp:ScriptManager>
5<asp:LinkButton ID="EditText" runat="server" CssClass="textr">Redigera texten</asp:LinkButton>
6<asp:Panel ID="ModalPanel" runat="server" CssClass="modalpu">
7 <asp:Button ID="btnBold" runat="server" Font-Bold="True" Text="F" Width="30px" />
8 <asp:Button ID="btnItalic" runat="server" Font-Italic="True" Text="K" Width="30px" />
9 <asp:Button ID="btnUnderline" runat="server" Font-Underline="True" Text="U" Width="30px" />
10 <asp:Button ID="btnHeader" runat="server" Text="Rubrik" Width="80px" />
11 <asp:Button ID="btnText" runat="server" Text="Text" Width="80px" /><br />
12 <asp:TextBox ID="tbContent" runat="server" Height="400px" Width="430px" TextMode="MultiLine" /><br />
13 <asp:Button ID="OKButton" runat="server" Font-Bold="True" Text="Skicka" Width="90px" />
14 <asp:Button ID="CancelButton" runat="server" Text="Avbryt" Width="90px" /><br />
15 <asp:Label ID="lblStatus" runat="server" />
16</asp:Panel>
17<cc1:ModalPopupExtender ID="ModalPopupExtender" runat="server"
18 TargetControlID="EditText"
19 PopupControlID="ModalPanel"
20 x="0"
21 Y="0"
22 DropShadow="true"
23 RepositionMode="none"
24 OkControlID="OKButton"
25 OnOkScript="__doPostBack('ctl00$Content$LoginView1$EditContentUserControl$OKButton','')"
26 CancelControlID="CancelButton"
27 BackgroundCssClass="modalbg" />
EditContent.ascx.vb
1Imports System.Configuration
2Imports System.Data.SqlClient
3Imports System.Data.SqlDbType
4Imports ErrorHandling
5
6PartialClass admin_EditContent
7Inherits System.Web.UI.UserControl
8
9Dim objConnAs New SqlConnection(ConfigurationManager.ConnectionStrings("SMK").ConnectionString)
10Private _textToEditAs String
11
12 Public WriteOnly Property TextToEdit()As String
13 Set(ByVal valueAs String)
14 _textToEdit = value
15End Set
16 End Property
17
18 Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load
19Dim objCmdAs New SqlCommand("SELECT [Text] FROM [Texts] WHERE [TextName] = @.TextName", objConn)
20
21Dim objParamAs New SqlParameter("@.TextName", VarChar)
22 objParam.Value = _textToEdit
23 objCmd.Parameters.Add(objParam)
24
25Try
26 objConn.Open()
27 tbContent.Text = objCmd.ExecuteScalar
28Catch exAs Exception
29 Err.Log(ex)
30Finally
31 If objConn IsNotNothing Then objConn.Close()
32End Try
33 End Sub
34
35 Protected Sub OKButton_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles OKButton.Click
36Dim objCmdAs New SqlCommand("UPDATE Texts SET [Text] = @.Text WHERE [TextName] = @.TextName", objConn)
37
38Dim objParamAs New SqlParameter("@.Text", VarChar)
39 objParam.Value = tbContent.Text
40 objCmd.Parameters.Add(objParam)
41
42 objParam =New SqlParameter("@.TextName", VarChar)
43 objParam.Value = _textToEdit
44 objCmd.Parameters.Add(objParam)
45
46Try
47 objConn.Open()
48 objCmd.ExecuteNonQuery()
49 lblStatus.Text ="Uppdaterat!"
50Catch exAs Exception
51 Err.Log(ex)
52Finally
53 If objConn IsNotNothing Then objConn.Close()
54End Try
55
56 objConn =Nothing
57 objCmd =Nothing
58 End Sub
59End Class



Hi Luken,

Would you please add this code to EditContent.ascx.vb?

protected override void OnPreRender(EventArgs e)
{
// add base.OnPreRender(e); at the beginning of the method.
base.OnPreRender(e);

// codes to handle with your controls.
...
}

I have copied your code to my project and did some modifications(comment and rename work only) , it works well on my machine. Also where's your master page? If it doesn't work, would you please create aworkable sample and give us the links so that we can download your project. Thanks

Best regards,

Jonathan


i'd love to add it to editcontent.ascx.vb, but i don't know how to re-write it to vb. i get syntax errors on "base" when i try. what is it called with vb syntax?


Hi Lycken,

For example,

C# code

protected override void OnPreRender(EventArgs e)
{
// add base.OnPreRender(e); at the beginning of the method.
base.OnPreRender(e);

// codes to handle with your controls.
...
}

Convert to VB Code,

Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs) ' add base.OnPreRender(e); at the beginning of the method. MyBase.OnPreRender(e) ' codes to handle with your controls.

End Sub

Here is anuseful tool.

I hope this help.

Best regards,

Jonathan


thanks a lot! it's working fine now - or at least this part of the solution is... i have a couple of other things that aren't doing so well at the moment, but i'll work on those for yet a while before i post here.

again, thanks!

Monday, March 26, 2012

Execute javascript doesnt work for popup calendar in AJAX

Hi I create a popup calendar and put the following code for clicking on calendar:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender1.Commit(Calendar1.SelectedDate.ToShortDateString())
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "setCursor", "alert(777);", True)
End Sub

Page.ClientScript.RegisterClientScriptBlock will cause javascript executed auto when I clicking on popup calendar. It works for ATLAS. But after I moved it to AJAX, it doesn't work. no response for this javascrpt.

Help please.

With ASP.NET AJAX Beta, you need to move to ScriptManager.RegisterClientScriptBlock instead of Page.ClientScript.RegisterClientScriptBlock.

Thanks. David.

But for my case, ScriptManager is put in master page. And the following code is put inside a user control (.ascx) and loaded dynamically.

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender1.Commit(Calendar1.SelectedDate.ToShortDateString())
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "setCursor", "alert(777);", True)
End Sub

How to get ScriptManager object in user control?


I changed the code as:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
PopupControlExtender1.Commit(Calendar1.SelectedDate.ToShortDateString())
Dim sm As Microsoft.Web.UI.ScriptManager
sm = Page.Master.FindControl("MasterScriptManager")
sm.RegisterClientScriptBlock(Me.Page, Me.GetType(), "setFocus", "alert(777);", True)
End Sub

it still doesn't work. Help please.



The Control parameter to RegisterClientScriptBlock (the first param) needs to specify a control that's inside the UpdatePanel that's being updated when the script block is to be updated. I suspect that Me.Page in your example does not satisfy that requirement, so please try a control that does.
Thank you so much, David.

Saturday, March 24, 2012

Exception with Asp.net Ajax 1.0 beta 2 + VS.net

Hi,

I have installed Asp.net Ajax 1.0 beta 2.0 on VS 2005. but whenever I create any new website using asp.net template, VS2005 is throwing following exception. I tried to installed couple of times but everytime VS.net is throwing same exception

"Package Microsoft.Web.AJAXExtension.Designer.VisualStudioToolbox.AJAXExtension,Version=1.0.61025.0,Culture=neutral, PublicKeyToken=null' has failed to load properly (GUID = {CF28F3C7-5DEE-44D1-9B49-E6EB5FD0E186})"

Thanks

The problem is in the?"PublicKeyToken=null".Try?to uninstall?Ajax?Beta?2?and?create?a?new?asp.net?website?to?
check?if?it?works. If?not, maybe?the?problem?is?in?Visual?Studio?.Net?2005. Otherwise?try?to?reboot?your?PC?and?re-install?Ajax?Beta?2?to?your?PC.?Please?give?us?a?reply?after?you?try?it.

Hi ,

Thanks for information. I found some problem in machine.config. after re-installed vs.net 2005, it is workign fine.

Thanks.

Exception / Error 500 on using UpdatePanel and postback of value starting with "less than"

We are using the December, 19, release of AJAX CTP (and Control Toolkit) and are noticing the following behaviour:

If you are putting for example a TextBox into an UpdatePanel, filling the box with a value like "<x" and do a postback of that value then you will receive the following error message:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

If you use empty braces (<>) everything works fine, if you uses only the closing brace (>) there is also no problem.

Does anybody have more detailed information on this problem or how to avoid it?

Regards,
ReneMT

put validaterequest="false" in the <%@. %> at the top.

NOTE: when you do this you must provide your own validation, because leave it out might introduce security risks of scripts injecting attacks.


Hmmm...

That may be a solution - but I think basically this is no real good one (as you are already pointing out) [:-)]. I thought about something like HTML encoding for postback values... Any possibilities in this direction?

ReneMT


hello.
well, not out of the box. btw, this is not an ajax problem...if you build a simple asp.net page, you'llget the same results.

Arrrrrrgh...

If this is a fact it is really sadIndifferent So in my eyes the only workaround were

Forbid input of the "<" sign or

I'm posting this response at the root because it may be beneficial...

I tried all the methods discussed here, but then I ran across a different thread in which they were running into a problem with all 3 releases (AJAX 1.0, CTPs, Atlas) where physical file names did not match up with the file name in the URL. Of course this can happen anytime you do a postback and the associated Code Behind (CB) page flips you out to a different page without updating the URL in the browser.

So my fix didn't involve any fix at all. I just went to the actual page (instead of being flipped over there by my CB code) andw00t! everything is kosher. I also tried using symbols discussed here (my AJAX dll versions are 1.0) and I verified that ICANput symbols in text fields with no resulting errors.

Please let me know if this is confusing.


I have a related problem with the TImer control in Ajax. I inject a <br> tag into a READ-ONLY text box, but when the Timer refreshes the TextBox I get the same error. Seehttp://forums.asp.net/thread/1626704.aspx

Ivan


I'm suddenly having this problem with FireFox 2.0.0.3. If my editor/textarea contains only text, good, if it's HTML - no go. Tried the ValidateRequest="false" hack, it did kinda work, but I ended up with firefox sending the old values from the textarea!

Anyone else working on this?


Any updates or fix on this issue?

Exapanding the CollapsiblePanelExtender in code

Hello,

I have the following collapsiblePanelExtender declared on my page. So initially it is collapsed...

<ajaxToolKit:CollapsiblePanelExtenderID="CollapsiblePanelExtenderCasing"runat="Server"TargetControlID="PanelCasingViewDetails"ExpandControlID="ImageExpand"

CollapseControlID="ImageExpand"Collapsed="True"ExpandedImage="~/images/collapse.gif"CollapsedImage="~/images/expand.gif"ImageControlID="ImageExpand"SuppressPostBack="true"/>

and I'm trying to cause it to expand in code using..

Me.CollapsiblePanelExtenderCasing.Collapsed =False

...but the panel does not expand after this line executes. Any ideas?

You need to set the clientstate to false before calling the collapsed property.

Me.CollapsiblePanelExtenderCasing.ClientState = False
Me.CollapsiblePanelExtenderCasing.Collapsed = False

I ran into the same issue when I was trying to programatically expand and collapse the panels. Just make sure you properly update the CollapsedImage and ExpandedImage as I am not positive on if those will update.

Let me know if that helps

JoeWeb


That was it. Thanks.

Wednesday, March 21, 2012

Events and ajax

Hi there

I have the following problem. I have a multiview within an updatepanel. When i activate a view within the multiview i want to do something. So i created OnActivate="vProperties_Activate" on the view. Now when i click a certain button i do this

mvContent.SetActiveView(vProperties);
upContent.Update();

Setting the activeview and updating the updatepanel. The problem is that vProperties_Activate is never reached. I got a same sort of problem when i create a button in the code behind and the event is never reached. Can someone help me with this?

Thnx in advance!

Is the button inside the UpdatePanel?

If not, is the button set up as a Trigger within the Update Panel?

I can't repro this. I set up the following markup and all events fire as expected:

C#

protected void Button1_Click(object sender, EventArgs e) {if (mv1.ActiveViewIndex == 0) { mv1.ActiveViewIndex = 1;//return; }else if (mv1.ActiveViewIndex == 1) { mv1.ActiveViewIndex = 2;//return; }else if (mv1.ActiveViewIndex == 2) { mv1.ActiveViewIndex = 0;//return; } UPD1.Update(); }protected void mv1_ActiveViewChanged(object sender, EventArgs e) {//Response.Write("Active View Index Chagned - " + mv1.ActiveViewIndex.ToString()); TextBox1.Text="Active View Index Changed - " + mv1.ActiveViewIndex.ToString(); }protected void view1_Activate(object sender, EventArgs e) { TextBox1.Text ="View 1 Activated!"; }
 
HTML:
 
<asp:UpdatePanel ID="UPD1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:MultiView runat="server" id="mv1" ActiveViewIndex="0" OnActiveViewChanged="mv1_ActiveViewChanged"> <asp:View runat="server" ID="view1" OnActivate="view1_Activate" > a</asp:View> <asp:View runat="server" ID="view2"> b</asp:View> <asp:View runat="server" ID="view3"> c</asp:View> </asp:MultiView> <asp:TextBox ID="TextBox1" runat="server" Height="152px" TextMode="MultiLine" Width="408px"></asp:TextBox> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

Ok thats not exactly what i have. I have created the multiview in the ASPX page with the different views. Then in the code behind i create the dynamic part of tblPropertiesForm. When i do it OnAtivate is doesnt work and when i do it OnInit it wors fine. Seems to be a viewstate issue. Problems is that i dont want to create all the views when the page loads. I also create the button in the code behind.

The MultiView is within an update panel

</p><p><asp:View ID="vProperties" runat="server" OnInit="vProperties_Init">
<asp:Table runat="server" ID="tblPropertiesForm">
<asp:TableRow>
<asp:TableCell ColumnSpan="2"><asp:Label ID="lblProperties" Text = "Eigenschappen" runat="server" CssClass="ContentHeader" Font-Bold="true"></asp:Label></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell Font-Bold="true">Omschrijving</asp:TableCell>
<asp:TableCell Font-Bold="true">Invoerveld</asp:TableCell>
</asp:TableRow>

</asp:Table>
</asp:View>


From the documentation, if you create controls and add them to the collection at any other time than Load or Init, they will behave unexpectedly.

LSU.Net:

From the documentation, if you create controls and add them to the collection at any other time than Load or Init, they will behave unexpectedly.

This means that when i want to create a (reasonable big) website with ajax i have to create ALL the views on the init of the views. Definitly not good for performance. Is there no way around that so i can still create the controls on the activate?

Thnx for your quick responses.


No. You see, if you create the controls at any other time, their corresponding events cannot fire because the page doesn't know about them.
Well now i think of it. The view itself is created in the ASPX page. I can create that in the init and set the onactivate. Then i should be able to create the other contols on the activate. I thought i tried that but maybe not... Could this work or is still something preventing the fire of the onactivate?
Ok the onactivate works now, but now a button thats created in the on_init and placed on the page within the onactivate doesnt fire his click event :(

Event handler gets removed after AJAX refresh.

Hi,

I add an event handler on window.onload.
However, this seems to get removed after AJAX refresh.

Following are steps to reproduce behavior.
What may I have missed.

Thanks.
yagimay

[steps]

1. Create an ASP.NET AJAX-Enabled Web Site.
2. Add ScriptManager, UpdatePanel and a TextBox (inside the panel) on web form.
3. Add following script block to web form.

<script type="text/javascript">
window.onload=init;
function init(){
var tx=$get("TextBox1");
$addHandler(tx,"click",txt_click);
}
function txt_click(e){
var tx=e.target;
alert(tx.id+": input numbers.");
}
</script>

4. Add following server side code.

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

Dim str As String = TextBox1.Text
If Not IsNumeric(str) Then
str = "N/A"
Else
Dim val As Double = Double.Parse(TextBox1.Text)
str = val.ToString("c")
End If
TextBox1.Text = str

End Sub

5. Debug.
6. Click TextBox.
-- TextBox.onclick event occurs (alert appears).
7. Input anything and press [Enter] key.
-- UpdatePanel refresh and TextBox.Text is updated.
8. Click TextBox.
-- TextBox.onclick event does not occurs anymore.

I was able to get this work by using PageRequestManager.add_pageLoaded instead of window.onload.

<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(init);

function init(sender,args){
var tx=$get("TextBox1");
$addHandler(tx,"click",txt_click);
}
function txt_click(e){
var tx=e.target;
alert(tx.id+": input numbers.");
}
</script>

Thanks.

yagimay