ラベル javascript の投稿を表示しています。 すべての投稿を表示
ラベル javascript の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Reset Button Onclick Adds WebForm_DoPostBackWithOptions

I'm trying simply call JavaScript to reset the form and this is added, I'm guessing, from script manager. When I click the reset butt on now, rather than resetting the form I get a postback. Any idea why script manager does this and what I can do to prevent the postback?

Hi Travich,

Here is the sample that you can reference to.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager><%=DateTime.Now.ToString()%> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <input id="Reset1" type="reset" value="reset" style="display:none" /> <asp:Button ID="Button1" runat="server" Text="ResetForm" OnClientClick="resetForm();return false;"/> <script language="javascript" type="text/javascript"> function resetForm(){ $get("Reset1").click(); } </script> </form></body></html>

I hope this help.

Best regards,

Jonathan

Reset Cascading Dropdown

I have a set of cascading dropdowns that I need to be able to programatically reset via javascript. I can change the selectedIndexes but that doesn't change any of the data "behind the scenes".

Thanks

Hi

Doesn't change any of the data "behind the scenes", What you mean?

Would you please post some code,so I can reproduce the problem and resolve it more quickly?

Thanks


As I have seen it for three cascading drop downs there are also three hidden form fields that contain data. My specific scenario was modifing some existing code that utilized three drop downs. The application was a store selector. The user could type in a postal code or use drop downs (Country, Region, City). I needed to reset the drop downs if a user types in a postal code. Setting up the blur event on the postal code text box was simple enough. But getting the drop-downs to reset was more challenging. I originally trimmed the item list down to the first item (please select). However on postback the original drop down selections came back. What I ended up doing was triming the item list and resetting the "hidden" fields to ":::" which is what the starting state appears to be.

There has to be an easier way to reset the drop downs to thier default state (via javascript). If the user simply sets the first drop down to the 0 index all drop downs reset. However, using using JS to set the selectedIndex property doesn't cause the client side event to fire.

Hopefully that helps a little. I am probably just missing something obvious. Is the client side JS code documented anywhere?

Resizable control as part of composite control

I'd like to use the ASP.NET AJAX Resizable control in my composite control. My control should provide all its images, JavaScript, and CSS as Embedded Resources, so that the users of it don't need to bother about these files. This includes the HandleGrip.png image that comes with the Resizable control. Unfortunately, the image use is defined in the css of the Resizable control, like this:

.handleText
{
width:16px;
height:16px;
background-image:url(images/HandleGrip.png);
overflow:hidden;
cursor:se-resize;
}

How can I let anyone use my control without giving them a copy of HandleGrip.png (to put somewhere on their website, while it is already embedded in my DLL)?

Hi,

You may refer to the the sample in AjaxControlToolkit. For instance:

.ajax__slider_h_rail {position:relative;background:url(<%=WebResource("AjaxControlToolkit.Slider.Images.slider_h_rail.gif")%>) repeat-x;height:22px;}


Indeed.

I triedbackground-image. Visual Studio did not let me (saying'url(<%=WebResource(' is not a valid value for the 'background-image' property.). After I read your comment I realized I could set the background-image by means of specifyingbackground.

Thanks.

ResizableControlExtender Handle Click Event

I would like to be able to fire the event that occurs when the user clicks on the handle

ResizableControlExtender from my own javascript code.

Do you know how to do this?

Your help is much appreciated.

Thak you very much

Hi,

Internally, this extender doesn't support such behavior.

You may add an resizebegin event handler to the extender, in this handler, call a asynchronous method to invoke to method on server side( web service or pageMethod ) .

So, you code may goes like this:

function pageLoad()

{

var re = $find("behaviorID of the resizableExtender");

re.add_resizebegin(onResizeBegin);

}

function onResizeBegin()

{

//invoke a service side method here.

}

Hope this helps.

2012年3月26日月曜日

Response.Redirect in a PostBack causes javascript error => workaround here

There's a problem in Atlas when calling a Response.Redirect on a postback (and the ScriptManager uses "EnablePartialRendering=true"). E.g. doing a Response.Redirect("otherpage.aspx") from the button-click event code.

There's a workaround, however.

Instead of doing:

Response.Redirect("otherpage.aspx");

do this:

Page.ClientScript.RegisterStartupScript(
this.GetType(), "redirect",
"window.location.href='otherpage.aspx';",true);

I wrote a custom httpmodule (acquirerequeststate event) that needed to do a response.redirect in certain cases. This threw the "unknown error" on atlas pages. I added "false" for the endReponse parameter and it works fine now. Response.Redirect("page.aspx",false).

thanks

Retaining GridView cell color on postback

I have a GridView in an UpdatePanel in which I use JavaScript to allow the user to change cell colors on the fly. It works great, until a postback occurs in which case, all of the user changes are lost. How do I maintain the cell colors after postback? I am trying to use a Save button to store the status of each cell to a database. Unfortunately, the cell colors are reset immediately, so even the save routine does not work correctly.

Thanks for any help you can provide,

Todd

Here is the script used to change the color of a cell when the user right-clicks on it:

<script type="text/javascript"><!-- /* script for changing the background color of the table cells based on the "Selection Mode" */ document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').onmousemove = MouseMove; document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').onmousedown = MouseMove; document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').oncontextmenu = DontShowContext; document.getElementById('ctl00_MainContentPlaceHolder_gvWafer').onmouseup = MouseUp; // handle the MouseMove event for the GridView control function MouseMove(event) { // IE doesn't pass the event object, so we have to pass it manually if (event == null) event = window.event; /* only select table cells if the right mouse button is pressed and the underlying item is a 'TD' element (table data) */ if (event.button == 2 && event.srcElement.tagName == 'TD') { var cell=event.srcElement; var cellValue=cell.innerHTML; /* display the row and column indexes in the browser status bar */ window.status="row, column = " + cell.cellIndex + "," + cell.parentElement.rowIndex; /* determine which item in the Selection Mode drop down list box is selected */ switch(document.getElementById( 'ctl00_MainContentPlaceHolder_ddlSelectMode').getAttribute( 'selectedIndex')) { case 1: // available /* Don't allow cells marked as QC Samples to be marked Available */ if (cell.style.backgroundColor != '#996600') { // GREEN cell.style.backgroundColor='#00FF00'; } break; case 2: // picked /* Don't allow cells marked as QC Samples to be marked as Picked */ if (cell.style.backgroundColor != '#996600') { if (cellValue >= 20 || cellValue <= 200) { // GRAY cell.style.backgroundColor='#999999'; } else { // WHITE cell.style.backgroundColor='#FFFFFF'; } } break; case 3: // reserved /* Don't allow cells marked as either Picked or QC Samples to be marked as Reserved */ if (cell.style.backgroundColor != '#996600' && cell.style.backgroundColor != '#999999') { if (cellValue >= 20 || cellValue <= 200) { // PURPLE cell.style.backgroundColor='#9933CC'; } else { // WHITE cell.style.backgroundColor='#FFFFFF'; } } break; default: return; } } } /* clear the status bar data */ function MouseUp(event) { window.status = ""; } /* handle the ContextMenu event for the GridView control - Don't show the default context menu */ function DontShowContext(event) { return false; } if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); // --></script>

You are going to need to save these styles and reinitalize them on the callback of the UpdatePanel e.g.:

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(EndRequestMethod);

prm.add_beginRequest(BeginRequestMethod);

...or you can add your logic to the server side. The problem is that you are rebinding the whole GridView and obviously client-side changes aren't persisted.

-Damien


Get the current PageRequestManager instane and

try to use beginRequest and endRequest


Thanks for both of your inputs. I don't know why I expected the JavaScript to make the changes to the GridView control. I forgot that the GridView control is rendered as a Table and that the JavaScript was simply modifying the Table. I actually took a little bit different route to solve the problem (I didn't see your replies until just a few minutes ago...had email notification turned off by mistake).

So, since the GridView is rendered as a Table and JavaScript cannot change GridView properties, I had to somehow track the changes that were made to the Table and propagate them to the GridView control.

I decided to create a TextBox control in which the JavaScript code would write the changes made to the cells (in the format "[row],[column]=[color]\n"). My VB code then parses out those changes and makes the corresponding change in the GridView control. I make the width and height of the TextBox zero so that it is not visible.

It may not be the best way to accomplish the task, but it is working. Since this is for an intranet application, and I have a ton more work to do, I am going to stick with it. The next time I run into a problem like this I will keep the other suggested solutions in mind.

Thanks,

Todd

Return a DataTable with Webservice and Bind via JavaScript

I am using a Webserivce method that returns a DataTable and in JavaScript I have this:

function pageLoad() {
ret = Dashboard.FetchQuadOne(OnCompleteOne, OnTimeOut, OnError);
ret = Dashboard.FetchQuadTwo(OnCompleteTwo, OnTimeOut, OnError);
}

function OnCompleteOne(result) {
document.getElementById('div1').innerHTML = result;
}

If I have my Webservice method, FetchQuadOne return a DataTable, how can I bind that to a GridView using JavaScript? Or is there a way to do this in the code-behind of my .aspx page? I guess I could just build an html table in my webservice method and return that, but it would be mugh each easier to bind the DataTable to a GridView.

I don't see how this could work, a DataTable is a .NET specific object. Javascript has no knowledge of how to consume that or for that matter any knowledge of how to bind to a .NET Datagrid. You could return xml or JSON and bind to some other data structure using XSL or roll your own.

Yeah, that is what I was afraid of. I thought maybe there would be someone way to put the JavaScript in the code-behind page and somehow bind the DataTable to a GirdView. I wanted all the built-in features of the GridView, like sorting and formating. O- well. I just wanted to make sure it wasn't possible before I head down an ugly road of building the table on the fly with the data.

Thanks.


Hi,

I think this article ofKazi Manzur Rashid can help you:http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx

This article will show you how to create an AJAX Grid and a generic pager, which mimics the built-in GridView control on the client side.

Best Regards,

2012年3月24日土曜日

Returning Exceptions

Hi

Using the example:
http://atlas.asp.net/quickstart/atlas/doc/services/default.aspx#catchingExceptions

Both IE and FF throw javascript errors

FF: result has no properties
IE: 'null' is null or not an object - 'null' being the result argument from the OnError callback method

See for youself:
http://atlas.asp.net/quickstart/atlas/samples/services/ExceptionPage.aspx

Is this a bug with the Jan06 release? What is the best way around this?

Craig

I just downloaded the Jan06 release and I'm experiencing the same problem...


Hi people,

i'm using January release also, when i run the example from the Atlas quickstart site, i got the same exceptions.

But if i try the example locally (copy the examples to my computer Atlas site), they are working well.

I think the Atlas site is using an older release.

So, Atlas team please, update the quickstart samples site. It's very important for the people who are starting with Atlas have confidence about the samples

This way it's much harder to find the errors.


Actually, I can reproduce the problem running the example locally. In my scenerio, I use an ASPX page to host the web method as follows:

MyPage.aspx.cs
[WebMethod]
public void GetData() {
throw new ArgumentException("throw exception");
}

MyPage.aspx
<scriptlanguage="javascript"type="text/javascript">
functionCallServer() {
PageMethods.GetData(,OnComplete, OnTimeout, OnError);
}

function OnComplete() {
alert("Complete");
}

function OnTimeout(result) {
alert(result);
}

function OnError(result) {
alert(result);
}
</script>

<!-- Call the server from a HTML button -->
<inputtype="button"value="Call Server"onclick="CallServer();"/>


you're right,

If i move the method to the same page, i got a null argument in the error delegate.

I tried to add

<atlas:ScriptManagerID="scriptManager"runat="server"EnablePartialRendering="true"

OnPageError="OnScriptManagerPageError">

<ErrorTemplate>

Ha ocurrido un error al procesar esta acción.<br/>

<spanid="errorMessageLabel"></span>

<hr/>

<buttonid="okButton"type="button">

OK</button>

</ErrorTemplate>

</atlas:ScriptManager>

and the server script

<scripttype="text/C#"runat="server">

[WebMethod]

publicvoid ExceptionTest(String someParam)

{

thrownewInvalidOperationException("foo");

}

protectedvoid OnScriptManagerPageError(object sender,PageErrorEventArgs e)

{

// Set e.ErrorMessage to something you want to send down to the client

e.ErrorMessage = (String.IsNullOrEmpty(e.Error.InnerException.Message)) ? e.Error.Message : e.Error.InnerException.Message;

}

</script>

as i have seen at

http://www.nikhilk.net/AtlasM1Refresh.aspx

and the server function OnScriptManagerError is not called, even i checked with fiddler that the server response code is 500.

I'd like to know how to use the new feature of page error handling


Same problem here.
I'm executing a WebMethod and the error handling are returning a null value.

Somone knows how to catch error returned from the WebMethod?

It's a bug in Jan06?


hello guys.

well, i may be wrong since i've only started lookig at atlas today and i've also got this bug while throwing exceptions from web methods defined on the page. after trying to do some debugging, it looks like the problem is on Web.Net.WebResponse.get_objectmethod. the problem is that it gets the result and tries to deserialize it. however, when a method on a page throws an error, the result that is received on the client part is an html page which de JSON can't deserialize. this seems like a bug on the scriptmanager (is this the component that handles server side processing when one calls methods on a page? - ehy, don't forget that i just started today on this :) )
Hi,

we can distinguish 3 cases:

1) The Exception is raised in a method defined in a WebService.
In this case, an instance of the class Web.Net.MethodRequestError issent to the client. This object exposes three properties that give infoon the particular Exception raised: get_message(), get_stackTrace(),get_exceptionType().

2) The Exception is raised during an asynchronous postback.
This means we have declared at least one UpdatePanel. The Exception canbe raised, for example, in an event handler during the Page lifecycle.
In this case, the ScriptManager is able to send the error message downto the client and to display it using its <ErrorTemplate />.Moreover, the server can format the message to be sent to the client byhandling the PageError event of the ScriptManager.

3) The Exception is raised when calling a [WebMethod] defined in a Page.
In this case, no exception handling is performed by the Atlasframework, and the client receives (in the response) the tipical HTMLpage that is displayed on ASP.NET pages when an Exception is raised.

At this point, the the error callback could be declared in this way:

function onError(objError, response) {
if(objError) {
// Got a MethodRequestError instance.
}
else {
// Custom error handling.
alert(response.get_statusCode());
}
}

While the objError parameter is null, the second parameter is theresponse object and we can use it to display, for example, an alertwith the HTTP status code (obviously, while waiting for an improved exception handling in the next release).
hello.

yes, i got into that conclusion after debugging the atlas script file...i think that it should be fixed before the final release...

Returning web service result from calling function in javascript (Atlas)

When using Atlas is there a way that I can call a web service method and have the result returned from the calling function. I understand that Atlas works asynchronously and therefore uses callback functions but I need the calling function to return the result somehow.

I tried something similar to the following but it didn't work. It seems to be that the global variable only gets updated once the calling function completes.

var getResult;
function LMSGetValue(param) {
// Note that the LMSAPI is setup with a ScriptManager
LMSAPI.LMSGetValue(param,LMSGetValueComplete);
pause(1000);// helper function that pauses by # millisecs
return getResult;
}
function LMSGetValueComplete(param) {
getResult = param;
}

The reason that I have to return the result from the calling function is that the javascript that calls the function (which is located in a iframe) follows a strict specification called SCORM which is used for building sharable elearning content and learning management systems (LMS). The learning content in the iframe calls the LMSGetValue function to get the data from the LMS and expects a return value.

Any help or suggestions on how I might be able make this scenario work would be grately appreciated as I really am quite stuck.

Unfortunately there is no current support for synchronous webservice calls, you cannot return a value from your method directly, the results are only available thru your callback.

Rich text editor in an update panel

I want to use a javascript editor like fckeditor in my webpage where the textarea is in an updatepanel.

But the textarea isn't is the welcome page, she apear when you click on a linkbutton.

How can i do for the editor to trigger when the textarea come or for the editor to load when i click the link.

Thanks in advance.I NEED YOU, HELP ME PLEASE

RightClick Menu

Dear Team

I am using ASP.NET2.0, C#, JavaScript, AJAX

I want to make a right click menu working on GridView, with some items inside the meun, and when I press on it I can handle it from Javascript or from server side and I can fill this menu from Server side if it is possible.

So how can I do that?

Thank you.

dear Team
i did use the control found in this site:http://msdn.microsoft.com/msdnmag/issues/05/02/CuttingEdge/

i am working with ASP.NET2.0, C#, AJAX, JAVASCRIPT.

if you please i want to know the following:
1 - why dose the context menu postback, i mean if i want only to use it in the client side, is there a way for it.
2 - i am using the context menu with a gridview so i want to know the current row index, from javascript and if possible from C# too.
3 - i want to know what i clicked on the menu from Javascript.

please advise me what to do.
i am stuck in this problem for 1 week now and i didnt find any solution.
i want you to know that i download the control and i use it sand it is working for me but i want to know these point that will solve my whole problem.

thank you so much in advance.
this is my Email:
zonzone@.hotmail.com