Showing posts with label sample. Show all posts
Showing posts with label sample. Show all posts

Monday, March 26, 2012

Programmatically use PostBackAction

Does anyone have a sample on how to correctly use the PostBackAction? I am having a bear of a time passing the eventargument and eventtarget properly when using this programmatically. Thanks.

Jon

Did you ever find any examples? I think I might need to use PostBackAction and it would be nice to have an example.

Steve

Saturday, March 24, 2012

Q From MS ajax sample

Why microsoft uses the code:

if ( typeof(Sys)!=="undefined" ) Sys.Application.notifyScriptLoaded() ;

and not

if ( typeof(Sys)!= "undefined" ) Sys.Application.notifyScriptLoaded() ;

Is it the same?

Leeor

=== and !== differ from == and != in that they avoid type coersion.

In this particular case, I'm not sure there's a difference, but in general the "strict equals" (=== and !==) operands are usually what you want.


Sorry but I didnt understand theprincipal difference


It's all about type coercion:

"100" == 100 // returns true, because the types are coerced
"100" === 100 // returns false, because the types have to first match before the comparison is even performed

Does that make sense?


That sounds alot betterWink

Thanks man

Wednesday, March 21, 2012

Question about the slider extender control and "hiding" the textbox it extends

Copied and pasted from the interactive sample pages, under slider tips:

TextBox visibility. The asp:TextBox that the Slider is upgrading will be visible during the page loading, so it is usable if JavaScript is not enabled on the browser. Depending on your requirements, you can prevent the asp:TextBox from being visible by setting its display mode to "none".

However, there is no display mode or displaymode property for the textbox control, nor for the slider extender. How then can I prevent the textbox from being visible while the page is loading?

Another question: is there a way to set the slider to enabled = "false" where it would show the value (e.g. the slider being at the middle of the rail for a value of 50%) without it being movable? I tried setting the textbox to enabled = false. The slider looks somewhat grayed out, but you can still click on the slider and move it. Thanks a lot.

Hi,

1) display is a CSS attribute. you should set display:none on the extended TextBox.

2) At the moment the slider can't be disabled, but this is a good suggestion.

Thanks.


Ah thanks. Forgot about the css attribute for that.

As for the slider not being enabled or disabled, I guess I'll just make it invisible for now.

Question with "Sample ASP.NET AJAX Client Application" and "Samples not defined" again!

Yes, I'm getting a "Samples not defined" in the "Sample ASP.NET AJAX Client Application"


If you search on this error message, there are lots of people witht the same question and I've gone through their responses and verified that everything is correct.

I've verified that (what I can think of):

The namespace and the class name match the javascript callThe web service file "HelloWorldService.asmx" exists and is in the same directory location as AjaxScript.aspx
Microsoft.Web.Script.Services; is included in "HelloWorldService.asmx"Microsoft.Web.Extension is registered in AjaxScript.aspx

I looked at the source of the .aspx page and there is one line in particular that caught my attention:

<script src="HelloWorldService.asmx/jsdebug"type="text/javascript"></script>
The question is, where is this jsdebug file live? I suspect that this is the problem that the sample can't find it. I've assumed
it was in the \winnnt\microsoft.net\... folder but I couldn't find it.
 Anyone have any ideas for fun?
Thanks, Tim
OS: Windows 2000 (5.0.2195: SP4)
Browser: Firefox 2.0/IE 6.0.2800.1106 (SP1)
 
Source Code for fun:
AjaxScript.aspx
 
1<%@dotnet.itags.org. Page Language="C#" Title="ASP.NET AJAX Script Walkthrough" %>2<%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="Microsoft.Web.UI" TagPrefix="asp" %>3456<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">78<html xmlns="http://www.w3.org/1999/xhtml">910 <head id="Head1" runat="server">11 <title />12 <style type="text/css">13 body { font: 11pt Trebuchet MS;14 font-color: #000000;15 padding-top: 72px;16 text-align: center }1718 .text { font: 8pt Trebuchet MS }19 </style>2021 </head>22 <body>23 <form id="Form1" runat="server">24 <asp:ScriptManager ID="ScriptManager" runat="server">25 <Services>26 <asp:ServiceReference path="~/HelloWorldService.asmx" />27 </Services>28 </asp:ScriptManager>29  30 <div>31 Search for32 <input id="SearchKey" type="text" />33 <input id="SearchButton" type="button" value="Search" onclick="DoSearch()" />34 </div>35 </form>36 <hr style="width: 300px" />37 <div>38 <span id="Results"></span>39 </div>40 <script type="text/javascript">4142 function DoSearch()43 {44debugger;45 var SrchElem = document.getElementById("SearchKey");46 Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);47 }4849 function OnRequestComplete(result)50 {51 var RsltElem = document.getElementById("Results");52 RsltElem.innerHTML = result;53 }5455 </script>56 </body>57</html>58

HelloWorldService.asmx

1<%@dotnet.itags.org. WebService Language="C#" Class="Samples.AspNet.HelloWorldService" %>23using System;4using System.Web;5using System.Web.Services;6using System.Web.Services.Protocols;7using Microsoft.Web.Script.Services;89namespace Samples.AspNet10{1112 [WebService(Namespace="http://tempuri.org/")]13 [WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]14 [Microsoft.Web.Script.Services.ScriptService]15 public class HelloWorldService : System.Web.Services.WebService16 {17 public HelloWorldService()18 {1920//Uncomment the following line if using designed components21 //InitializeComponent();22 }2324 [WebMethod]25 public string HelloWorld(String query)26 {27 string inputString = Server.HtmlEncode(query);28 if (!String.IsNullOrEmpty(inputString))29 {30 return(String.Format("Hello, you queriedfor {0}. The" +31 "current timeis {1}", inputString, DateTime.Now));32 }33 else34 {35 return("The querystring wasnull or empty");36 }37 }38 }39}40

Hi Tim,

Just to clarify, the line<script src="HelloWorldService.asmx/jsdebug"type="text/javascript"></script> is added because of the <asp:ServiceReference> tag in your aspx code.
Make sure that you added your HelloWorldService.asmx where your tag is pointing to:"~/HelloWorldService.asmx". It should be right under your web app root.

You can check the proxy object typing /js or /jsdebug after your web service address (e.g. http://your_web_app_address/web_service_name.asmx/js).

Hope this helps,

MaĆ­ra

Question: DynamicServicePath

In trying to troubleshoot my issues with the migration I noted that for the sample ModalPopUp example with the toolkit automatically populates the DynamicServicePath

From the toolkit example (Beta release )

Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground","CancelControlID":"ctl00_ContentPlaceHolder1_CancelButton","DropShadow":true,"DynamicServicePath":"/test/ModalPopup/ModalPopup.aspx","id":"ctl00_ContentPlaceHolder1_ModalPopupExtender","OkControlID":"ctl00_ContentPlaceHolder1_OkButton","OnOkScript":"onOk()","PopupControlID":"ctl00_ContentPlaceHolder1_Panel1"}, null, null, $get('ctl00_ContentPlaceHolder1_LinkButton1'));
});

In my application - all of my urls are dynamically served... and so for instance for this page url: /localhost/SitesEasyTest/admin/EditNamedPages/default.aspx

The following gets generated:

Sys.Application.add_init(function() {

$create(AjaxControlToolkit.ModalPopupBehavior, {"BackgroundCssClass":"modalBackground","DropShadow":true,"DynamicServicePath":"/SitesEasyTest/default.aspx","id":"PopUp","PopupControlID":"ctl00_ctl00_ctl00_PanelModal"}, null, null, $get('ctl00_ctl00_ctl00_Target'));

It is not grabbing the actual url that it should. In the ModalPopUp example and in my own code the DynamicServicePath is not declared it is added by the toolkit at runtime...

I attempted to correct the value via code behind:

MyPopUp = (ModalPopupExtender)GetOptionalControl(skin,"MyPopUp");

MyPopUp.DynamicServicePath = (CommunityGlobals.CalculatePath("Default.aspx")); // properly generates relative path url to the dynamic page

However, the following error is displayed when compiled and tested in a browser:

DynamicControlID must be set

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.ArgumentException: DynamicControlID must be set

[ArgumentException: DynamicControlID must be set] AjaxControlToolkit.DynamicPopulateExtenderControlBase.EnsureValid() +372 AjaxControlToolkit.ExtenderControlBase.GetScriptDescriptors(Control targetControl) +98 Microsoft.Web.UI.ExtenderControl.Microsoft.Web.UI.IExtenderControl.GetScriptDescriptors(Control targetControl) +7 Microsoft.Web.UI.ScriptControlManager.RegisterScriptsForExtenderControls() +187 Microsoft.Web.UI.ScriptManager.OnPreRender(EventArgs e) +402 System.Web.UI.Control.PreRenderRecursiveInternal() +77 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

In either case - the script generated does not generate a DynamicControlID by defaultand so it is puzzling why trying to 'correct' what is incorrect by ovveriding the value - would cause the error?

Does theDynamicServicePath have any purpose if you are not using the dynamic population feature? Otherwise can chalk this up as being a potential issue down the road if I start to use the dynamicservices features...

Thanks!

Relatively easy code fix for the Dynamic Service Path... For sites like mine where I do url rewriting as all content is database driven the following change needs to be applied:

in the ServicePathConverter.cs

namespace AjaxControlToolkit {

publicclassServicePathConverter :StringConverter {

publicoverrideobject ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value,Type destinationType) {

if (destinationType ==typeof(string)) {

string strValue = (string)value;

if (String.IsNullOrEmpty(strValue)) {

HttpContext currentContext =HttpContext.Current;

if (currentContext !=null) {

//OLD

// return currentContext.Request.FilePath;

//Changed by Jody to allow sites that rewrite urls not to

//have paths = /<root>/default.aspx

return currentContext.Request.RawUrl;

}

}

}

returnbase.ConvertTo(context, culture, value, destinationType);

}

}

}

Otherwise, on sites that manage dynamic content and generate urls - the path will always be the root...The filepath works if say you have all 'static' pages in folders etc... but not in dynamically generated scenarios. The code fix will allow for both styles of content to be served properly.

Questions - ModalPopup sample code

Hello, I'm trying to replicate the functionality presented here specific to the ModalPopup control:

http://ajax.asp.net/ajaxtoolkit/ModalPopup/ModalPopup.aspx

I've created a C# Ajax-enabled website project, have added the ScriptManager, ModalPopup, Panel and various Button controls, but although I've bound the ModalPopup to the button I want to have it use to activate my modal Panel, and though the project builds successfully, it doesn't react in the same way as the sample.

Here's the code from my skin file:

1<%@dotnet.itags.org. Page Language="C#" trace="true" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
23<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>45<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
6<html xmlns="http://www.w3.org/1999/xhtml">
7<head>
8 <title>Untitled Page</title>
9</head>
10<body>
1112 <form runat="server">
1314 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
15
16 <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px" Visible="False" >
17
18 <asp:Button ID="OkButton" runat="server" Text="OK"></asp:Button>
19 <asp:Button ID="CancelButton" runat="server" Text="Cancel"></asp:Button>
2021 </asp:Panel>
22
23 <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"24 TargetControlID="btnAddServer"25 PopupControlID="Panel1"26 BackgroundCssClass="modalBackground"27 DropShadow="true"28 OkControlID="OkButton"29 OnOkScript="onOk()"30 CancelControlID="CancelButton" />
31
32 <br />
33 <center>
3435
36 <asp:Panel ID="PanelMain" runat="server" Height="25px" Width="125px" HorizontalAlign="Center">
37
38 <asp:Button ID="btnAddServer" runat="server" Text="Add" Width="33px" /></td>
39
40 </asp:Panel>
41
42 </form>
43
44</body>
45</html>
46

At this point, I'm guessing that the missing piece of the puzzle lies with the CSS stuff and/or the master page, as that I haven't brought over from the sample project utilizing ModalPopup. Can someone please help me pinpoint what I'm missing that is preventing this from working?

Thanks in advance for any help. Smile

I found a fix which appears to work, but I'm still too much of a newbie to understand why. If someone could please explain I'd appreciate it.

After adding this to the "httpHandlers" section of my site project's Web.config file, my ModalPopup works:

<addverb="GET"path="ScriptResource.axd"type="Microsoft.Web.Handlers.ScriptResourceHandler"validate="false"/>

Thanks to this blogger: http://www.thecodinghumanist.com. The error I was encountering in the Javascript console (Firefox) was "Sys not defined", and the above appears to have addressed that, enabling the popup to work... somehow. Smile