Showing posts with label default. Show all posts
Showing posts with label default. Show all posts

Monday, March 26, 2012

PageMethods not found (Javascript Error)

Hey Guys,

the following is my aspx page

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

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

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

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

<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePageMethods="true"/>

<div>

<scripttype="text/javascript">

function getme()

{

PageMethods.getResults();

}

</script>

<asp:LabelID="lblText"runat="server"></asp:Label>

<inputtype="button"value="btnVal"onclick="getme();"/>

</div>

</form>

</body>

</html>

The following is my code behind

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.Services;

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

[WebMethod()]publicvoid getResults()

{

lblText.Text ="Sridhar";

}

}

The Current Version only support static method for Page Methods. So you cannot access the other element of the page.


Modify your page method return a string, then set lblText's value on the client side. This is an example of doing exactly that: http://encosia.com/index.php/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/

Saturday, March 24, 2012

Panel Default Button Event Doesnt Fire On Second Submit

I have one UpdatePanel surrounding a asp panel. Inside the panel I have one repeater, two buttons, and two labels. Inside the repeater's ItemTemplate I have an ImageButton and TextBox.

Here is the ASP Code:

1<asp:UpdatePanel ID="AdvancedSearchUpdatePanel" runat="server" UpdateMode="conditional" RenderMode="block" ChildrenAsTriggers="true">2 <ContentTemplate>3 <asp:Panel ID="AdvancedSearchPanel" runat="server" DefaultButton="SubmitSearchButton">4 <asp:Repeater ID="AdvancedSearchRepeater" runat="server">5 <HeaderTemplate>6 <table class="searchButton">7 <tr>8 <td colspan="100%">9 <asp:Label ID="KeywordLabel" runat="server" Text="Search By Keyword" Width="100%" Font-Bold="true"/>10 </td>11 </tr>12 </HeaderTemplate>13 <ItemTemplate>14 <tr>15 <td colspan="100%">16 <table cellpadding="0" cellspacing="0" style="padding-right:5px">17 <tr>18 <td>20 <asp:ImageButton ID="DeleteCriteriaButton" runat="server" ImageUrl="~/Resources/Images/close.gif" AlternateText="Click to Delete" OnClick="DeleteCriteriaButton_Click" />21 </td>22 <td>23 <asp:TextBox ID="KeywordTextBox" runat="server" Text='<%# Container.DataItem%>' CssClass="keywordSearch" Width="123px" OnTextChanged="KeywordTextBox_TextChanged" />24 </td>25 </tr>26 </table>27 </td>28 </tr>29 </ItemTemplate>30 <FooterTemplate>31 </table>32 </FooterTemplate>33 </asp:Repeater>34 <table class="searchButton">35 <tr>36 <td>37 <asp:Button ID="AddAnotherSearchButton" Text="Add Criteria" runat="server" OnClick="AddAnotherSearchButton_Click" />38 </td>39 <td>40 <asp:Button ID="SubmitSearchButton" Text="Submit Search" runat="server" OnClick="SubmitSearchButton_Click" />41 </td>42 </tr>43 <tr>44 <td colspan="100">45 <asp:Label ID="ReadableSqlString" runat="server" />46 </td>47 </tr>48 <tr>49 <td colspan="100">50 <asp:Label ID="ErrorLabel" runat="server" ForeColor="red"/>51 </td>52 </tr>53 </table>54 </asp:Panel>55 </ContentTemplate>56</asp:UpdatePanel>
My problem is that the default button for the panel is the SubmitSearchButton. 
On the first press of the enter key everything works as it should. 
On the second press of the enter key the DeleteCriteriaButton's (ImageButton) event gets fired because it is the first button in the panel. 
The only way I have seen to get around this is to put a button before the ImageButton that has a width of zero and have its event call the SubmitSearchButton event and everything works as should. 
Does anyone know a cleaner way around this problem or a reason this is happening. 
 
Thanks in advance.
There is a free component that allows you to assign a button to the "enter-pressed" client side event of input controls. If you type some text in textbox and press Enter, the form will postback, and the serverside click event of your button is fired.You don't need to write any code You only need to use control's "DefaultButton" property. It you are a beginner programmer this could be a life saver. More about MetaBuilders DefaultButtons Control you can find athttp://www.metabuilders.com/Tools/DefaultButtons.aspx
Wish this can help you.
You can specify a default button through javascript when pressing enter key.Try to take a look at this reading for details -http://www.beansoftware.com/ASP.NET-Tutorials/Accept-Enter-Key.aspx
Here are some sample codes for your reference.
TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; ");
Wish the above can help you.

DefaultButton is working fine for me on a simpler example:

<%@. Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void click(object sender, EventArgs e) { label1.Text = string.Format("{0} pressed at {1}", ((Control)sender).ID, DateTime.Now.ToString()); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="up1" runat="server"> <ContentTemplate> <asp:Panel ID="panel1" runat="server" DefaultButton="button2"> <asp:TextBox ID="text1" runat="server" /> <asp:Button ID="button1" runat="server" OnClick="click" Text="one" /> <asp:Button ID="button2" runat="server" OnClick="click" Text="two" /> </asp:Panel> <asp:Label ID="label1" runat="server" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

This does what you'd expect... every time you type something and press enter, the label displays "button2 pressed at " followed by the current time.

Your sample is considerably more complicated (and hard to reproduce, since I would need to provide a datasource etc.). Could you try simplifying your code to see at what point the issue goes away?


You can't forget that in my code I have repeaters. This might be the problem. My quick fix is to put a button before the delete button and set it to call the submit button's click event. I know this is a hack and I'm working on other issues. Your help is greatly appreciated. FYI, the datasource of the repeater is a List<string>.
I tested your code with a asp:Panel(asp:Repeater) in a asp:UpdatePanel in my PC.My test enviroment isWindows Server 2003 Enterprise,VS.NET 2005 and Ajax RC1.0. I found it?could?work?fine.If?you?click?the?TextBox?and?press?Enter?key in theasp:Panel, the?default?button?of?the?asp:Panel will?be?triggered.If?the?current?focus?was?moved to?the?outside?of?the?asp:Panel?and?press?Enter?key, the?default?button?of?the?asp:Panel?can't?be?triggered.So if you want to pressEnter key in anywhere of the current web form and the default button of theasp:Panel will be triggered, try to focus on aTextBox of theasp:Panel throughjavascript when pressingEnter key in the web form.This should work fine for you.
Sample Code: document.forms[0].elements['txtBox'].focus();
Wish this can help you.
This works in Internet Explorer 7, but not in Fire Fox 2. I'm soooo surprised.

Panel within Mutliview scrolls when contents of updatepanel updated??

Here is my page:
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXEnabledWebApplication1._Default" %><!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> <script type="text/javascript">var curCount = 0;var timer;var value = 0;function timedCount(){ try { var elem = document.getElementById('Panel1'); if (value == elem.scrollHeight) { } else if(value < elem.scrollHeight) { value = elem.scrollHeight; elem.scrollTop = value; } timer=setTimeout("timedCount()",100) } catch(err) { timer=setTimeout("timedCount()",100) } }function stopTimer(){ clearTimeout(timer);}</script> </head><body onload="timedCount()" onunload="stopTimer()" bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0"> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> </div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:Button ID="change" runat="server" OnClick="change_Click" Text="change" /> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> <asp:View ID="View1" runat="server"> <asp:Panel ID="Panel1" runat="server" Height="166px" ScrollBars="Auto" Width="173px"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Literal ID="Literal1" runat="server"></asp:Literal>  </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> </asp:Panel> </asp:View> <asp:View ID="View2" runat="server"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></asp:View> </asp:MultiView> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="change" EventName="Click" /> </Triggers> </asp:UpdatePanel> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick1"> </asp:Timer> </form></body></html>
 
 And here is the code behind:
 
protected void Button1_Click(object sender, EventArgs e) { Literal1.Text +="test<br>"; }protected void Timer1_Tick1(object sender, EventArgs e) { Random r =new Random();int j = r.Next(5000);if (j % 7 == 0) Literal1.Text +="test2<br>"; }protected void change_Click(object sender, EventArgs e) {if (MultiView1.ActiveViewIndex == 0) MultiView1.ActiveViewIndex = 1;else MultiView1.ActiveViewIndex = 0; } }
 
 
 the issue is that if I take Panel1 out of the MultiView it works fine: When dynamically updating Literal1, Panel1 correctly scrolls to the bottom and only when there has been a change in scrollHeight.
If Panel1 is moved to be inside View1, then Panel1 refreshes every second with the timer1.Tick event. What causes this behavior within the multiview, but not when Panel1 is outside of the Multiview?

after further testing, i have found that if I take the Multiview1 completely out of the UpdatePanel2 it works correctly too.


Each time tick probably causes an async postback. Since all your update panels are not set to have UpdateMode="Conditional", then they update on each async event


Thanks! That worked. One other question, i looked over the docs, but i havent been able to find any information on the cost/efficiency of this property. Is it more efficient to set them to "conditional" ?


I think more appropriate is to ask : What do I need :-) I think it is a.) a matter of convenience, and b.) sort of fool-proofing the facility - many ppl get confused when the thing updates all the time, and then others get confused when it doesnt. With "Always", you get refresh on each and all async postbacks on the page, which may be a waste of client-resources if the content does not need updating (the resources being spent on retrieving the control from viewstate, I guess). With Conditional, you are more in control as to when you get a refresh. Do remember than apart from the triggers , you can cause an UpdatePanel to update from your server-side code by calling the NameOfUpdatePanel.Update method.

Also, it gets a bit tricky conceptually when you have nested UpdatePanels - I m still exploring that confusion myself:)

Btw : if satisfied with the answer plz mark it as answered.


Wednesday, March 21, 2012

Parser Error with GoDaddy

Hi guys, I am in the middle of a website using Ajax with Godaddy, and getting this error as soon as I try to display my default.aspx. I have searched for hours on this, and cannot figure it out. Here is the page error that I get.

Server Error in '/' Application.

Parser Error

Description:An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message:Could not load file or assembly 'System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

Line 1: <%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>Line 2:Line 3: <%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856Ad364E35"Line 4: Namespace="System.Web.UI" TagPrefix="asp" %>Line 5:


Source File:/default.aspx Line:3

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

WRN: Assembly binding logging is turned OFF.To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.Note: There is some performance penalty associated with assembly bind failure logging.To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

I have AjaxControlToolkit.dll, AjaxControlToolkit.pdb, System.Web.Extensions.Design.dll and System.Web.Extensions.dll in the /bin folder in the root. I tried to email godaddy with this error, of course they say they dont support 3rd party software and suggest I convert to the virtual server, yea right... This was working up until yesterday, I am baffled. But I can say, it seems godaddy is not a good choice to host on up to this point. Any Ideas anyone?? I have read the other treads, tried all the suggestions and still get this error.

I appreciate it...

Chris

Hi Srbytes,

Based on your description, your problem seems most likely caused by the Version property:

srbytes:

Line 3: <%@. Register Assembly="System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856Ad364E35"Line 4: Namespace="System.Web.UI" TagPrefix="asp" %>

You'd better modify it like below.

<%@. Register Assembly="System.Web.Extensions,Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>

Based on my experience, I suggest that you should better add it to your web.config instead of each page.

Here is the url that you should folllow up: http://www.asp.net/AJAX/Documentation/Live/ConfiguringASPNETAJAX.aspx

I hope this helps.

Best regards,

Jonathan

Partial Page update using MenuItem and Ajax

Hello friends,

I am a new comer in your world.

I want to implement ajax in my site. My site has one default.aspx page. I use master page. In the master page there is a Menu.

I have a ContentPlaceHolder in Master page which is used in the default.aspx page. In the Menu each MenuItem has a NavigationUrl like

~/default.aspx?cid=. In the Page_load of default page i get the value of (cid) and load the (ascx) control in the PlaceHolder. And, as u know

the total page gives a PostBack I want to implement AJAX here. So that when a menu will be clicked only the Content of the PlaceHolder will

be updated. Hope i can make u understand !

Can any one help me with a guiding example......


To do something like that, an UpdatePanel isn't your best choice. You can use something like an IFRAME (http://www.w3schools.com/tags/tag_iframe.asp) or CSS to make the header static (seehttp://www.cssplay.co.uk/layouts/; a cool layout ishttp://www.cssplay.co.uk/layouts/fixit.html)

-Damien


Check it out:
http://geekswithblogs.net/rashid/archive/2007/08/11/Loading-UserControl-Dynamically-in-UpdatePanel.aspx


Sorry I didn't read your post correctly... I mentally skipped over the ASCX and saw ASPX. :) My previous post was based on that...

Sorry again,
-Damien


Sorry to reply late friends..

Thank u Kazi....

It worked fine....



Would you pls mark it as answer.


http://geekswithblogs.net/rashid/archive/2007/08/11/Loading-UserControl-Dynamically-in-UpdatePanel.aspx