Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Wednesday, March 28, 2012

Accessing PopupControl methods from client script

Hi,

How can I access the client-side functions of the PopupControl (namely "hide()")? Rather than the user having to click elsewhere on the page I also want to have a close button. According to the Firebug DOM explorer, the div element thats used for the popup has a property "PopupBehaviour" but trying to access this throws an error.

Cheers

Hi,

Not sure if this is the "correct" way to do this but I do this:

ButtonClose.Attributes.Add("OnClick","__AjaxControlToolkit_PopupControlBehavior_VisiblePopup.hidePopup();");

HTH

Jeff


I'm running into the same problem. I want to do a client-side close of the popupcontrol. I tried getting the uniqueid of the panel that's being popped up and setting the .style.display property to 'none' and that closes the panel but the problem is that whatever controls the panel used to cover are disabled. They've done this on purpose to disable controls from underneath the overlayed panel from being selected while you are selecting controls on the panel. So my solution half works.

Does anyone in the ASP team or someone who's had a need to close the popupcontrol control on the client-side have a clean a proper solution for this? Doing a postback to close the extender is a really stupid way of closing it so I'm sure someone must have come across this... Thanks!


Hi,

In version 1.0.10123.0 of the toolkit i do this on the client side which seems to work, as I said before I'm not sure if this is the correct way but it works.

AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup();
hth
Jeff 

I found this nice free popupcontrol. It comes with full source and also the .dll. Its nice to have this control in your Visual Studio Toolbox. ;)

Dainty Date


Jeff, thanks that works.


Cool. I will try that. Currently I use a button that calls "document.body.click()" to simulate the clicking elsewhere outside of the popup which effectively closes it.

Hi,

The easeist way to do this is add a BehaviorID="MyPopup" on the extender and then usevar behavior = $find('MyPopup'); in script.

Thanks,
Ted

Saturday, March 24, 2012

A Simple Atlas Work,but Still have Unknown Error BUG

Simply, i Place a Textbox and a button,when i click the button, it response.write(textbox1.text)
but, when i click the button, it show a java script pop-up and show me Unknown error..

below is the code:

1Default.aspx2<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" ValidateRequest="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>34<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">5<html xmlns="http://www.w3.org/1999/xhtml">6<head runat="server">7 <title>ASPNET_Atlas_Testing</title>8</head>9<body>10<form id="form1" runat="server">11<div>12 <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True"/>13<!-- This section of the page is wrapped by an UpdatePanel. -->14 <atlas:updatepanel id="up" runat="server" mode="Conditional" rendermode="Inline">15 <triggers>16 <atlas:controleventtrigger controlid="TextBox1" eventname="TextChanged" />17 </triggers>18 <contenttemplate>19 <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox><br/>20 </contenttemplate>21 </atlas:updatepanel>2223<!-- This section is also wrapped by an UpdatePanel. -->24 <atlas:updatepanel runat="server" id="up1" mode="Conditional" rendermode="Inline">25 <triggers>26 <atlas:controleventtrigger controlid="Button1" eventname="Click" />27 </triggers>28 <contenttemplate>29 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>30 </contenttemplate>31 </atlas:updatepanel>32</div>33</form>34</body>35</html>3637
1Default.vb23PartialClass _Default4Inherits System.Web.UI.Page56Protected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.Click7 Response.Write(TextBox1.Text)8End Sub910 Protected Sub TextBox1_TextChanged(ByVal senderAs Object,ByVal eAs System.EventArgs)11 Response.Write(TextBox1.Text)12End Sub13End Class1415
Check to make sure your web.config file is setup right and that your dll is in place (/bin) and not corrupt, as I'm not getting a javascript error when I try your code. It also doesn't work as you wrote it, though, and so I tried adding a label to one of the update panels and having the button change its value based on the text prop of the textbox1, and that worked fine. So I suspect that with update panels (this is just a guess) that you can't use Response.Write; whcih would make sense if you conceive of the Response object as passing a whole page rather than just the partial page the update panel is looking for.

Hi,

Remove all response.write statements & replace them with this.page.registerclientscriptblock(script);

Amit Lohogaonkar

mcp,mcad

lohogaonkaramit@.yahoo.com

A Script on this page is causing Internet Explorer to run slowly. If it continues to run,

I am getting a weird error when the Web Page Loads.

Stop running this script?

A Script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive.

Yes / No

The Web Page has the following AJAX Atlas Controls;

CollapsiblePanel, ModalPopup

The WebPage has a Parent and Child Repeater Control which has the ModalPopup Controls embedded in them for each record. The Modal Popups are used to display the details of each record as well as enable editting of these records.

Do let me know what could result in this error. Any help / suggestion would be appreciated.

Regards,

Abhijit

Please try your scenario with the recently available61121 release of the Toolkit (and ASP.NET AJAX Beta 2). If the problem persists, then please reply with acomplete, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

Wednesday, March 21, 2012

A problem when I use script manager, script manager proxy

I have an default.aspx and 3 link in that page. When I click to one of these links I want to load a usercontrol( ex: control1.ascx ) and in this user control I also use ajax in this control. Other Developer said that I must use a master page and declare a script manager in this page. In usercontrol I just need to use scriptmanagerproxy... But I don't know exactly what I have to do. Can you help me. Thanks all of you a lot.

Hi hamanhtuan,

Well the scriptmanagerproxy is an extended version of the scriptmanager. In your situation i think you can fix it with just a scriptmanager on your .aspx page and no scriptmanagerproxy on the user control. When your webpage contains a scriptmanager control and the usercontrol isn't you can still make use of the Ajax functionalities. keep in mind that when you deploy this usercontrol on an apsx page where you're not have a scriptmanager then it isn't working. The scriptmanagerproxy isn't a solution for this problem because the scriptmanagerproxy also needs a scriptmanager control. So drop a scriptmanager on your aspx page and other controls (Updatepanels) in your usercontrol and it will work. Hope it helps.

Regards


When I remove a scriptmanagerproxy on my controls and use Updatepanels in my usercontrol then my *.aspx can load these control. But in my control, I have a gridview, a refresh button and I want to auto update this gridview when click this button. How can I do this work ? Thank you for your last answer.

Hi hamanhtuan,

SO your gridview needs to be in the updatepanel and the button should be the trigger for the updatepanel. this will partial update the controls inside the update panel but take a look at the following:

Controls that Are Not Compatible with UpdatePanel Controls

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside anUpdatePanel control:

TreeView andMenu controls.


Thank you for your answers.

A bug in AJAX RC ScriptManager

I've been adopting MS AJAX Extensions, and founded a small bug, wich i would like to describe in that post.

It's about script registration order when using ScriptManager static methods. As I suppose, they should work same way as Page.ClientScript methods. But, they don't, wich i believe is a bug.

When someone registers more than one script via ScriptManager with different Control references, the order of script registration is undetermined. And ClientScriptManager (Page.ClientScript) registers scripts in order as they were registered in user code.

I've looked via reflector into the scriptmanager code, and it seems, the bug source is System.Web.UI.ScriptRegistrationManager+ScriptSubmitStatementEntry class wich stores registered script entries in a ScriptBlocks property of type Dictionary<Control, List<ScriptBlockEntry>>.

That effectively means, that when i register some scripts with same control entry, the order of registration is right, but when i pass different control instances - the order is undermined due to Dictionary implementation (HashTable).

So. If we have;

Control button1 = new Button();
Control button2 = new Button();

ScriptManager.RegisterClientScriptInclude(button1, ...)
ScriptManager.RegisterClientScriptInclude(button2, ...)

The second script may actually register before first one, wich can lead to a bugs. Because script registration order is important.

I'm not sure where to submit this, so i hope someone will fix it.

Hi...

I don't think that's a bug, actually. If you look at the "ClientScriptManager.RegisterStartupScript Method (Type, String, String)" documentation, under "Remarks", it notes that "...The script blocks are not guaranteed to be output in the order they are registered. ". It offers the suggestion that, if you need the scripts in a specific order, you should concatenate them together in a single string and register that.

Hope this helps.


Hm.. interesting point. There is no such remark on RegisterScriptInclude method.

And actually, it works as i described. Maintaining the order. I think scripts are stored in arbitary array or list inside page.

Still, even if it's not a formal bug, it clearly a wrong behavior. ScriptManager states that it's methods can be used simply instead Page.ClientScrip methods, and it's obviously not true in that case.

If you programmatically register includes, you often don't have an option of concatenation. And still need to maintain the correct order.


JiCheng, you're incorrect.

There is indeed a static RegisterScriptInclude method on the ScriptManager object in the RC. And no, you cannot simply use Page.ClientScript.RegisterScriptInclude instead. This won't work in asynchronous postback scenarios.

To answer the original question, multiple calls to RegisterClientScriptIncludeshould result in loading the scripts in the order you registered them. I did a quick test with just two files, and they loaded in order on the client. (I checked by putting an alert() in each, so I could watch what order the alerts popped up.) When I switched the order of the RegisterClientScriptInclude calls, the order switched on the client as well.

To sum up, I can't reproduce the behavior you're seeing (where order isn't guaranteed), but I would consider it a bug. Please share code that reproduces this bug so I can verify.


I gotScriptManager.RegisterClientScriptInclude Method (control, type, key, url) method from this document -http://ajax.asp.net/docs/mref/M_System_Web_UI_ScriptManager_RegisterClientScriptInclude_4_6597d783.aspx.

TheRegisterClientScriptInclude(Control, Type, String, String) method is used to register a client script file for a page or part of a page that is participating in partial-page updates. If your page or part of the page is not using partial-page updates and you want to register a client script file, use the ClientScriptManager class registration methods. You can get a reference to ClientScriptManager object from the ClientScript property of the page.

TheRegisterClientScriptInclude(Control, Type, String, String) method registers a client script file on the page by rendering a <script> element with a src attribute. The url parameter is used to set the src attribute of the <script> element. To resolve client URLs, use the ResolveClientUrl(String) method. This method uses the context of the URL on which it is called to resolve the path.

Both theRegisterClientScriptInclude(Control, Type, String, String) andRegisterClientScriptResource(Control, Type, String) methods load script files into the browser. If a script with the same type and key (for a script file) or type and resource name (for a script resource) is already loaded, the script is not reloaded. The script blocks that are loaded using these two methods should avoid script that executes inline functions and should instead should contain function definitions and other supporting definitions for your application.

Sample Codes as follows:

%@. 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">
public void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack)
Calendar1.SelectedDate = DateTime.Today;

}
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptInclude(
this,
typeof(Page),
"AlertScript",
ResolveClientUrl("~/scripts/script_alertdiv.js"));
}
protected void IncrementButton_Click(object sender, EventArgs e)
{
Calendar1.SelectedDate = Calendar1.SelectedDate.AddDays(1.0);
}
protected void DecrementButton_Click(object sender, EventArgs e)
{
Calendar1.SelectedDate = Calendar1.SelectedDate.AddDays(-1.0);
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ScriptManager RegisterClientScriptInclude</title>
<style type="text/css">
div.MessageStyle
{
background-color: Green;
top: 95%;
left: 1%;
position: absolute;
visibility: hidden;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server"/>

<script type="text/javascript">
Sys.WebForms.PageRequestManager.instance.add_endRequest(Notify);
</script>

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar1" runat="server"/>
<br />
Change the selected date:
<asp:Button runat="server" ID="DecrementButton" Text="-" OnClick="DecrementButton_Click" />
<asp:Button runat="server" ID="IncrementButton" Text="+" OnClick="IncrementButton_Click" />
</ContentTemplate>
</asp:UpdatePanel>

<div id="NotifyDiv" class="MessageStyle">
Updates are complete.
</div>
</div>
</form>
</body>
</html>


Note I have two typos in my first paragraph where I wrote "RegisterScriptInclude" instead of "RegisterClientScriptInclude." Sorry for any confusion.