Showing posts with label click. Show all posts
Showing posts with label click. Show all posts

Wednesday, March 28, 2012

Why javascript function can not be found in Firefox with a AJAX page?

Following page works fine with IE. When click on Html button, the javascript function is called and works fine.

But when run the same page in Firefox, it reported that the error as below:

myFunction is not defined

onclick(click clientX=0, clientY=0)

What's the possible reason and how to solve it?

--the page code:the page also include some Ajax toolkit and the code for that is omitted.

<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false" Codebehind="workshop.aspx.vb" Inherits="my.workshop" %>
<!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>Workshop Registeration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<link href="http://links.10026.com/?link=StyleSheet1.css" rel="stylesheet" type="text/css" />
<script type="text/jscript" language="javascript" >

function reset(){
document.workshop.reset();
}

function myFunction() {
alert("test");
}

</script
</head>
<body class="page">
<form id="workshop" runat="server">
<asp:ScriptManager runat="server" EnableScriptGlobalization="true" ID="MasterScriptManager"
EnablePartialRendering="true" ScriptMode="Release" AsyncPostBackTimeout="72000">
</asp:ScriptManager>
<div>
<table border="1" cellpadding="0" cellspacing="0">
<tr class="namearea">
<td align="center" class="dataarea">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="right" style="width: 50%">
<input class="jsbutton" onclick="javascript:myFunction();" type="button"
value="Button1" />
</td>
<td align="left" style="width: 50%; background-color: White;">
<br />
<asp:PlaceHolder ID="plcmyHolder" runat="server"></asp:PlaceHolder>
<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Change the script type from text/jscript to text/javascript and it'll work.

why Javascript doesnt work properly in updatepanel?

i wanna my gridview to change into editrow model by click any space in the row , so i wrote in the aspx page:

.....
<script type="text/javascript">
function ClickEvent(cId)
{
var id=cId;
document.getElementById("rowid").value=id;
document.getElementById("btnBindData").click();
}
</script>
.....

<asp:LinkButton ID="btnBindData" runat="server" OnClick="btnBindData_Click" Width="0px" style="width:0px; height:0px"></asp:LinkButton>
<input type="hidden" id="rowid" runat="server" /> //send clicked row index to editindex property

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="userName" HeaderText="userName" SortExpression="userName" />
<asp:BoundField DataField="userPassword" HeaderText="userPassword" SortExpression="userPassword" />
</Columns>
</asp:GridView>

In the aspx.cs file i wrote:

.......

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#dfe345'");

e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

e.Row.Attributes["style"] = "Cursor:hand";

e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.RowIndex + "')");

}
}

......

protected void btnBindData_Click(object sender, EventArgs e)
{
GridView1.EditIndex=Convert.Int32(this.rowid.Value);

.....

GridView1.DataBind();
}

It works well without UpdatePanel ,but when put the GridView in the UpdatePanel ,when I click the row, the GridView got disappeared.

Replace asp:LinkButton with asp:Button. If you want you can sorround your button with a hidden div (to hide from the user). Also add UseSubmitBehavior="false" to the asp:Button.

For example:

<div style="display: none; line-height: 0pt;">
<asp:Button id="btnBindData" runat="server" OnClick="btnBindData_Click" UseSubmitBehavior="false" />
</div>

Why must I double-click the Confirm/Cancel Buttons of a ConfirmButtonExtender

Hello everybody

I'm using ConfirmButtonExtenders in my pages, but I have got an issue with them: I must double click the confirm or cancel buttons in order for something to happen.

I've typed no code but

<ajaxControlToolkit:ConfirmButtonExtender runat="server" ID="CBESupprimerIB" TargetControlID="LBSupprimerAnnonce" ConfirmText="<%$ Resources:Resource, RLConfirmSuppression%>"></ajaxControlToolkit:ConfirmButtonExtender>

Why is this ?


Thanks for your help

Hi,

It's hard to tell why from your description. I tried it, and can't reproduce the issue.

Can you investigate more and be more specific about how to reproduce it?


Simple error that concentration would have helped me to catch:

I simply had two Extenders and both extended the same Button so that I needed two click twice to validate my choice.

Thank you for telling me to investigate more, this helped me find where the issue came from...

Why Response.Redirect() opens up a new browser window in AJAX?

I have an AJAX enabled page displayed in amodal dialog, When I click on a button that has a Response.Redirect() code, a new browser window gets opened, which is weird and not the behavior that I expect.

I should note that this page worked properly before adding the AJAX related stuff.

I highly appreciate any insight into this problem.

try use server.transfer


I had already tried the Server.Transfer but I got a client side alert: "Sys.WebForms.PageRequestManagerParserErrorException: The message recieved from the server could not be parsed,..."
Try to navigate to next page in Javascript instead of on Server side. I think this can solve the issue.

hello.

i think the problem is that submitting a page on a popup will open another window by default. you can workaround this by adding an iframe to your popup window which loads the page you need.


Thanks, I think the only workaround to my problem was to use the IFrame in the modal window, but still, I'm wondering why the use of Server.Transfer() caused the error in AJAX, and, why the Response.Redirect() would open up a new window, was I missing somthing or it's just the way AJAX works!

May I ask that Response.Redirect is logical/possible at all during a partial postback (for example in an updatepanel's button click event)?!

Simply move that specific button which yield Response.Redirect outside of the updatepanel, maybe it helps.


Yes, the button which yielded the Response.Redirect() or Server.Transfer() for that matter, was inside the UpdatePanel, I moved it outside the UpdatePanel and my problem was solved. Actually the UpdatePanel was inside a Container UserControl, I think I should make use of UpdatePanel more narrowly focused.

Thank you very much indeed.


response.redirect will be correctly interpreted by the ajax platform. you can check this by using ?a "normal" page. the problem that was happening here was related with modal dialogs and the issue described is not an ajax problem.

server.transfer won't work correctly with ajax and shouldn't be used from controls placed inside the updatepanel. this is understandable because partial postbacks expect to receive a predefined message from the server and whe you do a server.transfer you end up retunring a new page to the user which doesn't conform to the expected message.

So response.redirect works with ajax.

If ajax open the redirected page via javascript (maybe using window.open( ... ) ), that can be a problem.

Modern tabbed browsers are configurable how to treat popup pages from normal links or from javascript (new window, same window, new tab, disable totally javascript popups etc.)

I recommend for Robert to try the page in firefox, and play with advanced firefox settings (type about:config in the address bar, and play with "browser.link.open_newwindow.restriction" and similar settings, you can google for help how it works)

ps:

If the button must be in the updatepanel, maybe it is possible to register a script in the server side which open the new window by javascript (a more controlled way.)


I am also running into this problem and am unable to place the control outside of the Update Panel. I am not clear as to how an IFrame would be implemented. Is it meant that an IFrame should be used in place of the AJAX update panel or in addition to? How would this implementation work specifically?

Thanks for any information in advance.


MaybeScriptManager.RegisterPostBackControl could be used to eliminate this problem in some cases.

So leave your button (which has the codebehind redirect logic) in the updatepanel, but use the RegisterPostBackControl method so it will cause a full normal postback. That way you have a normal redirect, not the ajax client side redirect.


Thanks for the responses.

I did try the following on the control that is being clicked to fire the Redirect:

ScriptManager1.RegisterPostBackControl(this.testButton);

Unfortunately, this still launches a new window during the redirect.

Does anyone have any other ideas as to how i can do this? I would be open to attaching some javascript to the button in order to perform the redirect, however, I have already tried adding the following with no success:

ScriptManager.RegisterClientScriptBlock(this.buttonTest,this.buttonTest.GetType(),"Redirect","window.location = 'http://www.testpage.com'",true);


jriell:

I have already tried adding the following with no success:

ScriptManager.RegisterClientScriptBlock(this.buttonTest,this.buttonTest.GetType(),"Redirect","window.location = 'http://www.testpage.com'",true);

If you choose that way (custom client side redirect), I recommend the following to try:

Put a regular input button, link etc. in the updatepanel, for example:

<input type="button" value="test" onclick="window.location.replace( 'http://www.testpage.com' );" />

If that works, try the script withthe RegisterClientScriptBlock stuff.

why script enabled webservice making postback to server?

My WebPage has two textbox & one button.On button click I call script enabled webservice asynchronously still why my page go for postback to server?

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

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<headrunat="server">

<title>Untitled Page</title>

<scriptlanguage="javascript"type="text/javascript">

<!--

function Button1_onclick()

{

ret= WebService.Hello(document.getElementById('TextBox1').value,OnComplete,OnTimeOut,OnError);

return(true);

}

function OnComplete(args)

{

document.getElementById('TextBox2').value=args;

}

function OnTimeOut(args)

{

alert('Timeout');

}

function OnError(args)

{

alert('error');

}

// -->

</script>

</head>

<body>

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

<div>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="Button1_onclick();"/>

<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="WebService.asmx"/>

</Services>

</asp:ScriptManager>

</div>

</form>

</body>

</html>

===============================================

WebService

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

///<summary>

/// Summary description for WebService

///</summary>

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService()]

publicclassWebService : System.Web.Services.WebService {

public WebService () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

publicstring Hello(string msg) {

return"Hello"+msg;

}

}

function Button1_onclick()

{

ret= WebService.Hello(document.getElementById('TextBox1').value,OnComplete,OnTimeOut,OnError);

return false; // return(true); you need to return false instead of true. if you return false it doesn't do post back.

}

Thanks,

Kiran


Still same condition it does post back.I tried same application with HTML controls textboxes & button it works fine but when I tried with server side control it posts back


Hi,

can you post code that you used for testing.

Thanks,

Kiran


here is code with HTML textboxes & button for same script enabled webservice

<%@.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>

<scriptlanguage="javascript"type="text/javascript">

<!--

function Button1_onclick()

{

ret= WebService.Hello(document.getElementById('Text1').value,OnComplete,OnTimeOut,OnError);return(true);

}

function OnComplete(args)

{

document.getElementById('Text2').innerText=args;

}

function OnTimeOut(args)

{

alert('Timeout');

}

function OnError(args)

{

alert('error');

}

// -->

</script> </head>

<body>

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

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="WebService.asmx"/>

</Services>

</asp:ScriptManager>

<div>

<inputid="Text2"type="text"/>

<inputid="Text1"type="text"/>

<inputid="Button1"type="button"value="button"language="javascript"onclick="return Button1_onclick()"/>

</div>

</form> </body>

</html>


Hi,

function Button1_onclick() still returns true.

did you change it to return false. and tried it.

Thanks,

Kiran


yeah.......I did change it to false & tested it ,it does post back .The code which I posted doesn't postback but its withHTML control which works fine & I am trying to do same webservice code but with server control.

Hi,

can you change below code

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="Button1_onclick();"/>

to

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="return Button1_onclick();"/>

make sure that function is called. keep alert message in Button1_onclick function so you know that function got invoked when you click Button1_onclick.

Thanks,

Kiran


Thank you Kiran it works just fine.But I didn't get difference b/nButton1_onclick() & return Button1_onclick() could you please explain it?

Thanks

Manisha.


event = "return function()" if function returns false the event gets canceled.

if your case we are forcefully canceling onclick event by returning false.

event = "function()" doesn't matter what function returns.

Thanks,

Kiran

Monday, March 26, 2012

Will calling .click() fire an updatepanel Trigger?

This might seem a bit silly but...

Basically, I have a javascript function which calls the .click() method of a button, this button resides outside of any UpdatePanels

This button is also set as a trigger for one of my UpdatePanel controls.

My problem is, the button click runs fine, the server side click event fires ok and rebinds some data for a GridView which is inside the UpdatePanel, but the UpdatePanel does not update its contents.

Do you have to physically click the button with your mouse to cause the Trigger? Or should the programmatic javascript call to click() work?

No will not cause it trigger, you need a postback for that, not a javascript call


You cantrigger an UpdatePanel refresh from the client side, using __doPostBack().

Hi

The programmatic javascript call to click() should work, you must do something wrong.

Look this sample:

<%@. Page Language="C#" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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>
<link href="http://links.10026.com/?link=StyleSheet.css" mce_href="StyleSheet.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
var styleToSelect;
function onOk() {
$get('Paragraph1').className = styleToSelect;
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<p id="Paragraph1">
GetContentFillerTextGetContentFillerTextGetContentFillerTextGetContentFillerText</p>
<br />
<ajaxToolkit:Accordion ID="Accordion1" runat="server" ContentCssClass="grey" FadeTransitions="false"
FramesPerSecond="25" TransitionDuration="250" HeaderCssClass="dimgreen" EnableViewState="true">
<Panes>
<ajaxToolkit:AccordionPane runat="server" ID="PaneOne">
<Header>
AccordionPane0
</Header>
<Content>
<a href="http://links.10026.com/?link=javascript:return false" onclick="javascript: LinkButton1.click()">Click here to change
the paragraph style</a>

</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>
<div style="visibility: hidden">
<asp:LinkButton ID="LinkButton1" runat="server" Text="Click here to change the paragraph style" /></div>
<asp:Panel ID="Panel1" runat="server" Style="display: none" CssClass="modalPopup">
<asp:Panel ID="Panel3" runat="server" Style="cursor: move; background-color: #DDDDDD;
border: solid 1px Gray; color: Black">
<div>
<p>
Choose the paragraph style you would like:</p>
</div>
</asp:Panel>
<div>
<p>
<input type="radio" name="Radio" id="RadioA" checked="checked" onclick="styleToSelect = 'sampleStyleA';" />
<label for="RadioA" class="sampleStyleA" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioB" onclick="styleToSelect = 'sampleStyleB';" />
<label for="RadioB" class="sampleStyleB" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioC" onclick="styleToSelect = 'sampleStyleC';" />
<label for="RadioC" class="sampleStyleC" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p>
<input type="radio" name="Radio" id="RadioD" onclick="styleToSelect = 'sampleStyleD';" />
<label for="RadioD" class="sampleStyleD" style="padding: 3px;">
Sample paragraph text</label>
</p>
<p style="text-align: center;">
<asp:Button ID="OkButton" runat="server" Text="OK" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</p>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server"TargetControlID="LinkButton1"
PopupControlID="Panel1" BackgroundCssClass="modalBackground" OkControlID="OkButton"
OnOkScript="onOk()" CancelControlID="CancelButton" DropShadow="true" PopupDragHandleControlID="Panel3" />
</div>
</form>
</body>
</html>

Thanks

Saturday, March 24, 2012

Wizard inside of update panel, still getting postbacks

Hi,

I placed a wizard inside of an update panel and when I click on the button for the next step, I still get a postback. I have tried setting the mode to conditional and it still occurs.

I even tried making a new atlas website and putting nothing but the update panel with the wizard inside and it still does not work. Here is the code below. Any idea what I am doing wrong??

<atlas:ScriptManagerID="ScriptManager1"runat="server"/><div><atlas:UpdatePanelID="UpdatePanel1"runat="server"Mode="Conditional"><ContentTemplate><asp:WizardID="Wizard1"runat="server"><WizardSteps><asp:WizardSteprunat="server"Title="Step 1"></asp:WizardStep><asp:WizardSteprunat="server"Title="Step 2"></asp:WizardStep></WizardSteps></asp:Wizard></ContentTemplate></atlas:UpdatePanel>

Hi,

it seems that you are not setting EnablePartialRendering="True" in the ScriptManager control.

Yes you are right. In the sample code I pasted that was the problem (and I feel very stupid). However in my actual code I did remember to set partial rendering to true.

Now, that being said, I think I figured out what was wrong, and hopefully the Atlas guys watching this forum can tell us if I am correct.

A little more background on the page first, it is a content page and the master page has a flash banner on it that I put their using the asp.net 2.0 flash control. On my developoment machine I didn't have the flash file it was pointing to. Instead of throwing an exception when I view the page in my browser it just kept perpetually loading the page.

It occured to me that the update panel may not work properly if the page had never completed loading before a postback was called. All I had to do was copy the flash file from the webserver to my development system and VOILA! The page loads, the update panel works.


Hi,

glad to hear that you solved it :) I'll bookmark this post for future reference.

Wednesday, March 21, 2012

Writing first extender control

Hi,

I am writing my first extender control to populate a text box with some value on click event of button. But I am missing something hence the extendercontrol is not gettting instanitated and also inserting debugger doesn't break into it. Can someone please help here?

Here is the code:

JS:


Type.registerNamespace('Toolkit');

Toolkit.DisableButtonBehavior = function(element) {
Toolkit.DisableButtonBehavior.initializeBase(this, [element]);
this._button = null;
this._textBox1 = null;
}

Toolkit.DisableButtonBehavior.prototype = {
initialize : function() {
/// <summary>
/// Initialize the behavior
/// </summary>
debugger;
this._button = this.get_element();
Toolkit.DisableButtonBehavior.callBaseMethod(this, 'initialize');
this._clickHandler = Function.createDelegate(this, this._onClick);
$addHandler(this._button, "click", this._clickHandler);
this._AlertHeader();
},

dispose : function() {
/// <summary>
/// Dispose the behavior
/// </summary>
Toolkit.DisableButtonBehavior.callBaseMethod(this, 'dispose');
},

_onClick : function() {
this._AlertHeader();
},

get_TextBox1 : function() {
return this._textBox1;
},
set_TextBox1 : function(value) {
debugger;
this._textBox1 = value;
},
_AlertHeader : function () {
this._textBox1.value = 'test5';
}
}

Toolkit.DisableButtonBehavior.registerClass('Toolkit.DisableButtonBehavior', AjaxControlToolkit.BehaviorBase);


if( Sys && Sys.Application ){
Sys.Application.notifyScriptLoaded();
}

Extender Class:

using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using System.ComponentModel.Design;
using AjaxControlToolkit;

[assembly: System.Web.UI.WebResource("Toolkit.DisableButtonExtender.DisableButtonBehavior.js", "text/javascript")]

namespace Toolkit
{
[ClientScriptResource("Toolkit.DisableButtonBehavior", "Toolkit.DisableButtonExtender.DisableButtonBehavior.js")]
[TargetControlType(typeof(Control))]
public class DisableButtonExtender : ExtenderControlBase
{
[IDReferenceProperty(typeof(Control))]
[DefaultValue("")]
[ExtenderControlProperty]
[ElementReference()]
public string TextBox1
{
get { return GetPropertyValue("TextBox1", ""); }
set { SetPropertyValue("TextBox1", value); }
}
}
}

ASPX:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Testpage.aspx.cs" Inherits="Testpage" %>
<%@dotnet.itags.org. Register Assembly="Toolkit" Namespace="Toolkit" TagPrefix="toolkit" %
<!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>
</head>
<body>
<asp:ScriptManager ID="scriptmanager" runat="server"></asp:ScriptManager>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button"/>

</div>
</form>
<toolkit:DisableButtonExtender ID="DisableButtonExtender" runat="server" TargetControlID="Button1" TextBox1="TextBox1"></toolkit:DisableButtonExtender>
</body>
</html>

Thanks

Hi,

The only problem I can find in your code is that the ScriptManager and the Extender are placed out of the form. When I modified this and run, it worked fine.

I created a ClassLibrary project, then added the following code into it:

using System;using System.Web.UI.WebControls;using System.Web.UI;using System.ComponentModel;using System.ComponentModel.Design;using AjaxControlToolkit;[assembly: System.Web.UI.WebResource("ClassLibrary1.DisableButtonBehavior.js","text/javascript")]namespace Toolkit{ [ClientScriptResource("ClassLibrary1.DisableButtonBehavior","ClassLibrary1.DisableButtonBehavior.js")] [TargetControlType(typeof(Control))]public class DisableButtonExtender : ExtenderControlBase { [IDReferenceProperty(typeof(Control))] [DefaultValue("")] [ExtenderControlProperty] [ElementReference()]public string TextBox1 {get {return GetPropertyValue("TextBox1",""); }set { SetPropertyValue("TextBox1",value); } } }}

This js file is set as EmbededResources

Type.registerNamespace('ClassLibrary1');ClassLibrary1.DisableButtonBehavior = function(element) { ClassLibrary1.DisableButtonBehavior.initializeBase(this, [element]); this._button = null; this._textBox1 = null;}ClassLibrary1.DisableButtonBehavior.prototype = { initialize : function() { /// <summary> /// Initialize the behavior /// </summary> debugger; this._button = this.get_element(); ClassLibrary1.DisableButtonBehavior.callBaseMethod(this, 'initialize'); this._clickHandler = Function.createDelegate(this, this._onClick); $addHandler(this._button, "click", this._clickHandler); this._AlertHeader(); }, dispose : function() { /// <summary> /// Dispose the behavior /// </summary> ClassLibrary1.DisableButtonBehavior.callBaseMethod(this, 'dispose'); }, _onClick : function() { this._AlertHeader(); }, get_TextBox1 : function() { return this._textBox1; }, set_TextBox1 : function(value) { debugger; this._textBox1 = value; }, _AlertHeader : function () { this._textBox1.value = 'test5'; }}ClassLibrary1.DisableButtonBehavior.registerClass('ClassLibrary1.DisableButtonBehavior', AjaxControlToolkit.BehaviorBase); if( Sys && Sys.Application ){ Sys.Application.notifyScriptLoaded();}

Then used the following page to test it and it worked fine:

<%@. Page Language="C#" %><%@. Register Namespace="Toolkit" Assembly="ClassLibrary1" TagPrefix="toolkit" %><!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 id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="scriptmanager" runat="server"></asp:ScriptManager> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button"/> <toolkit:DisableButtonExtender ID="DisableButtonExtender" runat="server" TargetControlID="Button1" TextBox1="TextBox1"></toolkit:DisableButtonExtender> </div> </form> </body></html>

Thanks Raymond. Getting script manager within form tag worked.


Writing Javascript in Usercontrol

Hi All,

My UserControl is having some linkbuttons. Whenever i click those linkbutton i need to show and hide some 'div' elements on the page on which im placing the usecontrol. What im doing is.

Code in LinkButton of UserControl

string scriptBlock ="";

scriptBlock +="<script language='javascript' src='/system/Js/changeclass.js'>";

scriptBlock +="hidecontent123();"; // Here "hidecontent123 is the function that which im calling from the source file 'changeclass.js'.

scriptBlock +="</script>";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"doSomething", scriptBlock);

hidecontent123() function:

function hidecontent123()

{

document.getElementById('previsible3').className='hidden';

}

Now im placing this UserControl in the webpage. In this page im having the 'div' tag with id 'previsible3', that which im hiding using the javascript function. First of all its not even going in to the function 'hidecontent123()'.

With the above code im not able hide the 'div' tag that which i want. Can anyone plz help me out in this.

Thanks in Advance,

Rajak Shaik.

I can't see where you're adding the Javascript call to the LinkButton.

LinkButton1.Attributes("onclick") = "hidecontent123()"

Presumably 'hidden' is a CSS class with 'display:none;' or similar? In your function you could do this:

document.getElementById('previsible3').style.display = 'none';

Bear in mind that the rendered ID of your element will change in a user control, so you could add the ClientID to you function:

LinkButton1.Attributes("onclick") = "hidecontent123('" & previsible3.ClientID & "')"

Then:

function hidecontent123(theDiv)
{
document.getElementById(theDiv).style.display = 'none';
}

Also bear in mind that changes like these will not be persisted across postback.

(code untested!)


Forgot to mention, the LinkButton will cause a postback unless you prevent it. If it posts back, your changes (hiding the div) will be lost unless you save the current value(s) to a hidden field that can be accessed server-side.

To prevent postback:

LinkButton1.Attributes("onclick") = "return hidecontent123('" & previsible3.ClientID & "')"

function hidecontent123(theDiv)
{
document.getElementById(theDiv).style.display = 'none';
return false;
}