Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Monday, March 26, 2012

Want to call a javascript function from code behind

Hi.

I am trying to call a javascript function on button click, buttton is present in update panel. It is not working.

On button click event handler i m writing the following code

Response.Write("<script>functionname();</script>");

I have added script reference in script manager and given the path.

Response.Write("<script>functionname();</script>") --> this works if button is outside update panel.

Help me...

Why not try placing your javascript function name in the button's OnClientClick parameter? That way it calls it directly without requiring a post back...

OnClientClick = "functionname();"


PhunkNugget:

If you do that, which runs first, the javascript in the client or the

click event code in the code behind? may be related, so it's

important to know..I also need to invoke a modal popup

extender from code in a codebehind, not from a click event..

I'm watching this thread closely.. Geeked

Thanks in advance..


The OnClientClick runs first.


Kanwar,

You can't use Response.Write() inside an update panel. It conflicts with the ajax somehow (very annoying). You can attach the script to your button's onclick event in page load such as the following:

string myString="<script language='Javascript'>\n";

myString+="function fuctionname()\n";

myString+="{\n";

myString+="whatever your function does...\n";

myString+=

"}\n";myString+="</script>\n";

Page.RegisterClientScriptBlock(

"MYFUNCTION", myString);

btnMyButton.Attributes.Add(

"onClick","functionname();");

Then when you click on the MyButton, the javascript function will be called.

Saturday, March 24, 2012

want to pass datatable (.net) to javascript function

hello,

i have a datatable stored at page level (in aspx). i am binding this datatable to gridview object which has a checkbox column for row selection.this table may contain about 500 to 1000 records. when ever i check/uncheck this checkbox, i want to update this bound datatable without posting back to server.is it possible through ajax/javascript ?

pl. provide solution for this asap...

Jayesh Shah

You will have to post back to the server if you want to update the DataTable as that is a server side object. However, you could use a UpdatePanel around the GridView to hide the fact that a full postback is occurring.

Watermark extender type function on a dropdown?

Hi there,

I have 5 textboxes all using the watermark extender to tell the user that these fields are required and has some colour formatting. I would also like to do the same type of thing to a dropdown but it doesn't work, can anyone suggest a method I can use?

Thank you for your time

Here's just one suggestion:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="Default4" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><%@. Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><!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"> function ddlChange(ddl) { if (ddl.selectedIndex == 0) { ddl.style.backgroundColor = 'Yellow'; ddl.options[0].innerText = 'Please select...'; } else { ddl.style.backgroundColor = ''; ddl.options[0].innerText = ''; } } </script></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:DropDownList ID="DropDownList1" runat="server" style="background-color:Yellow;" onchange="ddlChange(this)"> <asp:ListItem Value="">Please select...</asp:ListItem> <asp:ListItem>Option A</asp:ListItem> <asp:ListItem>Option B</asp:ListItem> <asp:ListItem>Option C</asp:ListItem> </asp:DropDownList> </div> </form></body></html>

Thats cool thank you for that! one question, can css be used in place of hardcoding the color?

Thanks again


Pretty simply really, use the same javascript example as above

Create a new Required style for the dropdown e.g background-color:red; have that as the dropdown list's default css then using this piece of javascript be able to swap between the 2 based on Item value

function ddlChange(ddl)

{
if (ddl.selectedIndex == 0)
{
ddl.className ='RequiredCSS'
}
else
{
ddl.className ='SelectedCSS';
}
}

Hope this helps you out.


awesome thank you

Boy, diverdan, I do all the hard typing and you get all the credit!

Just kidding.

Happy Holidays, all...


Sorry!!!! I thought I had clicked the both of you!

Thank you for your help! have a great holiday!

Wednesday, March 21, 2012

Web Methodst that returns DataTable gives me exception error " "circular reference was det

Hello,

I am getting this error "circular reference was detected while serializing an object of type". The Method GetRecords() is a function that returns DataTable type.. It happens the same thing when i return DataSet as well.

Any help?

Thanks

function GetStatusRecord() {

// Invoke the Echo method on the server.

PageMethods.GetRecords('1', onComplete);

debugger;

// Callback function.

function onComplete(result) {

// Display the echoed string.

alert(result);

}

returnfalse

}

The latest version of Asp.net Ajax no longer allows to serialize DataTable and DataSet anymore.


you are probably right, i havent updated asp.net ajax for about 6 months.

Web Part PartChromeType.None Causes Zone_ToggleDropCues Function Problem

Using the Atlas March CTP, I receive an error using it's webpart stuff.

It is in "function Zone_ToggleDropCues(show, index, ignoreOutline)"

this.initialize = function() {
Sys.UI.Controls.WebParts.WebPart.callBaseMethod(this, "initialize");

_titleElement.detachEvent("onmousedown", WebPart_OnMouseDown);
this.element.detachEvent("ondragstart", WebPart_OnDragStart);
this.element.detachEvent("ondrag", WebPart_OnDrag);
this.element.detachEvent("ondragend", WebPart_OnDragEnd);

if (_zone.get_webPartManager().get_allowPageDesign() && _zone.get_allowLayoutChange()) {
_titleElement.attachEvent("onmousedown", Function.createDelegate(this, mouseDownHandler));
}
}


"_titleElement.detachEvent("onmousedown", WebPart_OnMouseDown);"
says that _titleElement is null.

This happens when I set the chrometype to none for the webpart.

Nathan

We should be handling the case where _titleElement is null. I've filed a bug and this should be fixed in the next release of Atlas. Thanks for reporting it.

-Mike

Web service class undefined on Client load

Having tested a simple atlas web method call from the client which is fired by calling a javascript function on a button client side click event -it works perfectly.

The problem is I need this function called when the page loads, however whenever calling this function from either the body onload client side event or by using the RegisterStratupScript on the server side page load method, I get a javascript error refering to the web service class name as being undefined.

In theory this should work, Am I missing something regarding my understanding of the atlas lifecycle perhaps?

Please help!
Thanks

Dynamic script references (included in the References section of the ScriptManager) are not available until after page loading. To use these, you need to hook the Load event of the Application object. Declaratively, you can do this with:

<application>

<load>

<invokeMethod method="MyMethodName" />

</load>

</application>

Alternatively, you can statically include the service with a <script> tag.


A simpler syntax to do this is to have:

<application load="OnApplicationLoad" />

This goes into your <components>. So you would have something like this:

<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
<application load="OnApplicationLoad" />
</components>
</page>
</script>

David


BTW, I should mention that there is yet an easier way: just name your method pageLoad and it will be automatically called without having to be registered. See theAtlas docs for some examples.

David