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

2012年3月28日水曜日

ResizableControlExtender OnClientResize firing onload :-(

I have a ResizableControlExtender on my page. I set the OnClientResize to a js function with an alert. When I load the page, the alert pops. As expected, the alert pops on resize too, but I don't want the js function to be called on load. Is this a bug or expected behavior?

Thanks,

figz

Anyone?

To clarify (since it was Friday afternoon when I wrote the original post)...

Here is my ResizableControlExtender:

<ajaxToolkit:ResizableControlExtender ID="rceWrapper" runat="server" TargetControlID="panWrapper" HandleCssClass="handleWrapper"
MaximumHeight="0" MinimumWidth="960" BehaviorID="rceWrapper" OnClientResize="sayHello" />

Here is my js:

function sayHello(){alert('hello');}

The problem is when I load the page, the alert pops up. I would expect this to ONLY happen OnClientResize. So the question is, is this a bug or expected behavior? Thanks!


Hi Figz,

As far as I know, when the ResizableControlExtender control be initialized , it will call its _resizeControl(x, y, width,height) function. So that caused your problem.

To resolve this problem , my solution is to use a flag which will be set to true at pageLoad event. Just like this:

<script type="text/javascript" language="javascript">
var flag = false;
function pageLoad(){
flag = true;
}
function OnClientResizeText(sender, eventArgs) {
if(flag){
//your code;
}
}

</script>

Now , only when the flag is true , alert is allowed to be executed.

Another solution is attaching your javascript function on pageLoad event instead of defining as the ResizableControlExtender's property. Just like this.

<script type="text/javascript" language="javascript">
function pageLoad(){
$find('ResizableControlBehaviorID').add_resizing(OnClientResizeText)
}
function OnClientResizeText(sender, eventArgs) {
}

</script>

I hope this help.

Best regards,

Jonathan


Success! Thanks so much! For the record, I used the second option of attaching the js function on pageLoad instead of declaring it as a property. It worked like a charm!

2012年3月26日月曜日

Response.Redirect not working while inside an Update Panel

I have a link button inside an update panel. When the user clicks this button, it calls a function that performs a database update and then redirects them to another page. However, Response.Redirect isn't working with AJAX. Any suggestions how I can do this? Thanks!Can you post your code here?

Hi,

Reponse.Redirect works with UpdatePanel. Please refer to this sample:

<%@. 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"> protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("http://www.microsoft.com"); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

2012年3月24日土曜日

Returning a dataset from a web service

Say I have a page that calls a web service from a client function to get some data to bind a gridView like this:

-------------------

<scripttype="text/javascript"language="JavaScript">

function GetDataSet(){

var ds = SimpleService.ActiveProcess();

}

</script >

-------------------

And the web service looks something like this:

-------------------

[WebMethod]

public datasetActiveProcess(){

string connectionString ="Connstring stuff here";

DataSet ds = csql.GetActiveProcess(connectionString);

return ds;

}

-------------------

Of course, because I'm posting this problem, this isn't the correct way to implement this kind of solution...

Question is: Is there a better way? Or how do I manage to handle and display what's being returned from this web service in the web page?

thanks.

doug

This issue is associated with an Atlas Web Service call.

Here is a crude solution that I still need to refine:

------------------------

1. JavasScript call to webservice:

------------------------

function fnSetTimeout( ){

//this is the call to the web service.

var ds = SimpleService.ActiveProcess(OnComplete, OnTimeout);

}

------------------------

2. Webservice method

------------------------

[WebMethod]

publicstring ActiveProcess(){

string connectionString ="Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=simple2;Data Source=local

string xmlReader = csql.GetActiveProcess(connectionString);

return xmlReader;

}

------------------------

3 Webservice method

------------------------

publicstring GetActiveProcess(string connString)

{

string strSQL ="Select id, threadid, conversationId from ActiveProcess";

SqlConnection conn =newSqlConnection(connString);

SqlDataAdapter da =newSqlDataAdapter(strSQL, conn);

DataSet ds =newDataSet();

try

{

conn.Open();

da.Fill(ds);

XmlDataDocument xmlDataDocument =newXmlDataDocument(ds);

return xmlDataDocument.OuterXml.ToString();

}

catch (SqlException ex)

{

returnnull;

}

}

------------------------

3 Load the XML into parser

------------------------

/*==============================================================================

function: OnComplete

paramaters: result

Purpose: Gets the results from the ATLAS call and parses into an XML document

Date: 12/21/2005

==============================================================================*/

function OnComplete(result)

{

//Load XML

var XMLDoc =new ActiveXObject("Microsoft.XMLDOM");

try

{

XMLDoc.loadXML(result);

}

catch(err)

{

alert(err.description);

}

//Load XSL

var XSLDoc =new ActiveXObject("Microsoft.XMLDOM");

try

{

XSLDoc.async =false;

XSLDoc.load("ActiveRecords.xsl");

}

catch(err)

{

alert(err.description);

}

//Write the results of the transformation out to the div.

document.all.divTable.innerHTML = XMLDoc.transformNode(XSLDoc);

}

Here's the XSL if you're interested:

<?xmlversion="1.0"encoding="utf-8"?>

<xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:templatematch="/">

<html>

<head>

<title>Active</title>

<style>

copy { font-family: Arial, Verdana;}

h1 { font-family: Arial, Verdana; font-size: 14pt;}

p { font-family: Arial, Verdana; font-size: 10pt;}

</style>

</head>

<body>

<p><fontface="verdana">Active</font></p>

<tableborder="1">

<tr>

<thclass="copy">ID</th>

<thclass="copy">Thread Id</th>

<thclass="copy">Configuration ID</th>

</tr>

<xsl:for-eachselect ="NewDataSet/Table">

<tr>

<td>

<xsl:value-ofselect="id"/>

</td>

<td>

<xsl:value-ofselect="threadid"/>

</td>

<td>

<xsl:value-ofselect="conversationId"/>

</td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

thanks...

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.