Showing posts with label scriptmanager. Show all posts
Showing posts with label scriptmanager. Show all posts

Wednesday, March 28, 2012

dynamic generated clientside javascript

hi,

how can i register a script on asyncPostBack and can check in the next asynPostback if the script is on side ?

i use ajax with scriptmanager and updatepanel on my website.

sometimes i will give the user (after a asyncPostBack) a alert-message about javascript...

i have tryed following:

PrivateSub RegisterMsg(ByVal strMessageAsString,ByVal strScriptTagAsString)

Dim strScriptAsString ="alert(""" & strMessage &""");"

If (Not Page.ClientScript.IsClientScriptBlockRegistered("key"))Then

ScriptManager.RegisterClientScriptBlock(Me,Me.GetType(),"key", strScript,True)

EndIf

EndSub

the IsClientScriptBlockRegistered-methode every time gives false back...thx

Use ScriptManager.RegisterStartupScript() and drop the IsBlockRegistered check.


now i have:

Private Sub RegisterMsg(ByVal strMessage As String, ByVal strScriptTag As String)
Dim strScript As String = "alert(""" & strMessage & """);"

If (Not Page.ClientScript.IsClientScriptBlockRegistered("key")) Then
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "key", strScript, True)
End If
End Sub

and it is the same...it did not work correct, the IsClientScriptBlockRegistered-Method returns every time false and because of this the script will be written a second one, and third one and so on...


Hi,

Since the script is created dynamically, it won't be persisted between different requests.

So, before the method is called on the second request, this script block does not exist.

And my suggestion is you don't have to call this multiple times, just call it on initial request and it'll always stay on the page since the page isn't fully refreshed.


the problem is that the appl. dont makes really postbacks during running, only partial postbacks...

and my wish is that i will register and unregister scripts during partial postbacks...how can i do it ?


For partial postback, you can register new scripts.

But you can't unregister existed scripts on server side.


Has there been any progress made on this issue? I am just experiencing this now.

I've overriden OnInit with the following (similar) code:

if (!Page.ClientScript.IsClientScriptBlockRegistered(typeof(Page),"MyScript")
{
// use StringBuilder/StringWriter to build script
ScriptManager.RegisterClientScriptBlock(this,typeof(Page),"MyScript",sb.ToString(),true);
}
 
But the conditional is always true so the script gets recreated every time there is an asyncPostback.
One thing I noticed (using Firebug in Firefox) is on the initial load of the page the script is created
within the form and then on each successive asyncPostback a new script is created in the <head>.
Why is there no IsClientScriptBlockRegistered function in the ScriptManager class? Is that the problem?
That the Page.ClientScript and ScriptManager are looking at two different collections of scripts?

Monday, March 26, 2012

Dynacly add scriptmanager when needed?

Hi,

I'm trying to create a Web User Control that uses asp.net Ajax. I'd like it to find out if a scriptmanager already exists in the page and, if not, add ti dynamically. Would such a thing be possible?


Thanks in advance for any help.


Regards,

Stefan

Yes its possible, you can check if ScriptManager is registered. FindControl(); or you can added it in the Master Page

http://forums.asp.net/thread/1441992.aspx

http://forums.asp.net/thread/1436775.aspx


Thanks for your quick reply. But how would I use FindControl if I don't know what the name of the scriptmanager would be?

I'm thinking of a situation where my control gets used in combination with other ajax controls, or gets used multpile times on a form. (Actually, my control would be a DotNetNuke module)

Any ideas?


If you didn't change it ScriptManager1


I know, but the hard thing is, that all controls get added to the page dynamically by DotNetNuke. This means I'm pretty sure the name won't be ScriptManager1...

So if there's no other way than to use findcontrol, the only option would be to add the ScripManager to the page itself somehow.


Thanks for your help.



hello.

you can get a reference to the ScriptManager control by using the static GetCurret method. If there's already a ScriptManager on the page, you will get a non null value.

I've put together an example ofUsing Control Adapters to automatically attach AJAX Extenders to ASP.NET Controls, which isn't exactly what you want, but there is code for walking through the controls on a page to see if there is already a ScriptManager or ScriptManagerProxy ...

http://damianblog.com/2006/11/16/adapters-and-extenders/

Damian


hello.

hum...why are you going through a cicle to get the scriptmanager control?


Because I'm doing it from an HttpModule ... and also because I didn't know of the static method :-)

Not sure if it will work in the module though ... will have a go.

Damian


hello.

well, i guess it might not work if you haven't instantiated the master page (which is easily solved by just "touching" the property)


Hi again, it's been a while since I had time to figure this thing out, but your answers look promising. Thanks a lot so far.

DropShadowExtender; Showing up on Top

I am using VS2008 and the included AJAX Control ToolKit

I have a master page that includes the scriptmanager and a panel with the DropShadowExtender

I have added a content page, that has a panel with a DropShadowExtender.

When the page displays, the 2nd DropShadow, goes UP, and displays on the top of the box. Basically an UPShadowExtender.

Any ideas to correct?

I have noticed a similar situation in the past if I am using tables or panels (and I would presume divs as well since panels are rendered as divs) I am trying to recall exactly what solved the issue but I do recall it had something to do with the width of each of the elements. I beleive if I had a table and had the extender to another control within that table, and the content in that table forced the outter table (or panel) to expand, I noticed that the dropshadow extender would push upwards.

Basically, what Im trying to say is, check your table, div, panel widths and heights. Make sure the content has ample room.


Hi,

Thank you for your post!

Create a simple repro for this issue if you can,and please post up the whole code of the repro.

Anyway, I agree withjgilmore. you should do moretroubleshoot wok and then you can provide us with more valuable information.

Best Regards,

Saturday, March 24, 2012

DropShadow Extender: Opacity-property problem

I create Atlas-website, put ScriptManager on top of the page, add panel and set height, width and background-color properties. Then i add AtlasToolkit Dropdown Extender on the page ja set it's properties. My problem is that the dropshadow is only visible when Opacity is set to 1.0. If I set Opacity-property to less than 1.0 eg. 0.75, Panel-control doesn't show drop shadow. Am I missing something?

DropShadow-sample page works though..

Which browser are you using? But you're saying the sample is working okay, so I'm not sure what's wrong. If opacity is 1.0, the extender doesn't bother to apply the OpacityBehavior, which manages the opacity property. It would be interesting to see if the OpacityBehavior works on your panel. Maybe take a closer look at any differences between the sample and your page?


I'm using IE6 & IE7.

This markup with opacity set to .7 doesn't show dropshadow for panel:

<%@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"%>

<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit"%>

<!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>mySample Page</title>

<styletype="text/css">

.panelStyle {

width:350px;

height:250px;

background:#517dbf;

}

</style>

</head>

<body>

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

<atlas:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<asp:PanelID="Panel1"runat="server"CssClass="panelStyle">

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="DropShadowExtender1"runat="server">

<atlasToolkit:DropShadowProperties

TargetControlID="Panel1"

Width="5"

Opacity=".75"

TrackPosition="true"

Rounded="false"/>

</atlasToolkit:DropShadowExtender>

</div>

</form>

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>

But when I add the checboxlist w/ onclick-events from the samplepage , dropshadow is visible when checkbox is checked: now opacity values from .25 to .75 are working ok.

On DesignView DropShadowExtender1-Control displays error-text: 'TargetProperties' could not be initialized. Details: 'TargetProperties' could not be added to the collection. Details: 'dsBehavior' could not be set on property 'ID'. Doesn't throw any run-time errors.

<%@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"%>

<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit"%>

<!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>mySample Page</title>

<styletype="text/css">

.panelStyle {

width:350px;

height:250px;

background:#517dbf;

}

</style>

</head>

<body>

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

<atlas:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

<asp:PanelID="Panel1"runat="server"CssClass="panelStyle">

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="DropShadowExtender1"runat="server">

<atlasToolkit:DropShadowProperties

ID="dsBehavior"

Opacity=".75"

Rounded="false"

TargetControlID="Panel1"

TrackPosition="true"

Width="5"/>

</atlasToolkit:DropShadowExtender>

</div>

<divstyle="padding: 15px;">

<labelfor="chkShadow">

Show Drop Shadow:

</label>

<inputid="chkShadow"checked="checked"onclick="var b = $object('dsBehavior'); b.set_Width(chkShadow.checked ? 5 : 0);"

type="checkbox"/><br/>

<labelfor="chkRounded">

Rounded:

</label>

<inputid="chkRounded"checked="checked"onclick="var b = $object('dsBehavior'); b.set_Rounded(chkRounded.checked);"

type="checkbox"/>

<div>

Opacity:

<inputid="opacity25"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value=".25"/><labelfor="opacity25">25%</label>

<inputid="opacity50"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value=".5"/><labelfor="opacity50">50%</label>

<inputid="opacity75"checked="checked"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value=".75"/><labelfor="opacity75">75%</label>

<inputid="opacity100"name="opacityValues"onclick="$object('dsBehavior').set_Opacity(this.value);"

type="radio"value="1.0"/><labelfor="opacity100">100%</label>

</div>

</div>

</form>

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>


My best guess is that this has something to do with your video card/driver. I'm not sure how IE (or FireFox) does opacity but your first sample works fine for me for all Opacity values. Note I also do not get the design time errors you're mentioning, but that shouldn't affect the runtime behavior. Does it work in other browsers for you?

I've tried with FF & IE and two different laptops with same results (both laptops have VS 2005 Team Developer installed). I don't think it's video card/driver 'cause SamplePage's checkboxlist w/ onclick-events works ok. (BTW i have NVIDIA FX 1400 Go 256Mt-video card.) DesignView error happens when I add ID-property for the DropShadowProperties. Error disappears when I remove ID-property.

IntelliSense shows only "Opacity, Rounded, TargetControlID, TrackPosition and Width"-properties, no Id-property? I uninstalled and reinstalled all Atlas relatud stuff and created a new Atlas-website, but no dropshadow with opacity less than 1.0.

I'll keep digging.. or just use CSS-based dropshadows..Sad [:(]


This markup displays default dropshadow with opacity 1.0:

<

atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/><div>
<asp:PanelID="Panel1"CssClass="panelStyle"runat="server"></asp:Panel>
<atlasToolkit:DropShadowExtenderID="DropShadowExtender1"runat="server"EnableViewState="true">
<atlasToolkit:DropShadowPropertiesTargetControlID="Panel1"/>
</atlasToolkit:DropShadowExtender>
</div>

BTW) Why tagprefix is cc1 and not atlasToolkit (you have to manually change it)

From the DropShadowProperties.cs:

// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// Seehttp://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.


using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using Microsoft.AtlasControlExtender;

namespace AtlasControlToolkit
{
public class DropShadowProperties : TargetControlPropertiesBase<Panel>
{

/// <summary>
/// The opacity of the shadow, from 0 (transparent - no shadow rendered) to 1.0, which is fully opaque black.
///The default is .5.
/// </summary>
[DefaultValue(1.0f)]<-- This is not default .5
public float Opacity
{
get
{
return GetPropertyValue<float>("Opacity", 1.0f);<-- This is not default .5
}
set
{
SetPropertyValue<float>("Opacity", value);
}
}


Yes, that's a documentation bug, thanks for pointing it out.

The tag prefixes are arbitrary. They default to "cc1" or whatever, there isn't any way to specify them automatically.

Thanks!


Oh - the ID field is marked Browsable(false) so it won't show up in intellisense.

It's not needed in the 90% case and you can get yourself in trouble (e.g. if you use it in a repeater) so it's hidden.

Dropdownlist not working within an UpdatePanel

I have a MasterPage with a ScriptManager EnablePartialRendering set to true.

On my AddDeceseadInfo.aspx page I have multipe textboxes and a dropdownlist all wrapped in a UpdatePanel. Also on the AddDeceasedInfo.aspx page (content) I have a ProxyScriptManager.

When I pick a value from the Dropdownlist the value is always "".

When I set AutoPostBack to true my ValidationControl fires and tells me the dropdownlist can not be empty which at that point it is.

When I set the AutoPostBack to false once a pick a value from the dropdownlist all the data in the dropdownlist disappears.

Can somebody help out a AJAX newbie............Cheers!

protectedvoid Page_Load(object sender,EventArgs e)

{

TextBoxFirstName.Focus();

if (!IsPostBack)

{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

}

}

protectedvoid ButtonReset_Click(object sender,EventArgs e)

{

Utility.WebUtility.ClearAllTextBoxes(this);

}

protectedvoid ButtonSubmit_Click(object sender,EventArgs e)

{

if (Page.IsValid)

{

string firstName =HttpUtility.HtmlEncode(TextBoxFirstName.Text).Trim();

string middleName =HttpUtility.HtmlEncode(TextBoxMiddleName.Text).Trim();

string lastName =HttpUtility.HtmlEncode(TextBoxLastName.Text).Trim();

string nickName =HttpUtility.HtmlEncode(TextBoxNickName.Text).Trim();

DateTime dateOfBirth =Convert.ToDateTime(HttpUtility.HtmlEncode(TextBoxDateOfBirth.Text).Trim());

DateTime dateOfDeath =Convert.ToDateTime(HttpUtility.HtmlEncode(TextBoxDateOfDeath.Text).Trim());

int causeOfDeathID =Convert.ToInt32(DropDownListCauseOfDeath.SelectedValue);string birthPlace =HttpUtility.HtmlEncode(TextBoxBirthPlace.Text).Trim();

}

else

{

}

}

}

Set AutoPostBack to true and also set CauseValidation property to false


Set the EnableClientScript property to false on your validation control. Validators aren't supported in an UpdatePanel, this may be causing you issues,see Item #4 for more information

-Damien


I guess my post was not clear but the answers posted did not really help. My DropDownList is inside an UpdatePanel.

The ScriptManager is set to enable patial rendering.

AutoPostBack is set to true.

My UpdatePanel has UpdateMode set to Conditional

I populate the DropDownList with values from my database. When the page loads the values are there in the DropDownList. When I go and pick a value the data from the DropDownList disappears. Basically I end up with a empty DropDownList. Values gone................

When I set the AutoPostBack property to false the data stays in the DropDownList after I pick a value but when I hit the submit button the Validation control fires because the DropDownList is all of a sudden empty again.

I am running the latest Versions of ASP.Net Ajax and was under the impress the validator problems have been solved in the latest version. It seems to work on all my other froms that I use the UpdatePanel. The Validator controls and UpdatePanel work nicely together.

There seem to be no examples on the web where somebody has on DropDownList in an UpdatePanel and simple wants to get the value from that DropDownList and the additional TextBoxes once the Submit button is clicked.

I watched some of the ASP.Net videos and there are some Extenders that might be useful but it is too much work. Isn't there a why of making a simple DropDownList work within a UpdatePanel. So I can get the value from it.


How are you binding the list; are you possibly clearing it on the postback? Do you have ViewState enabled for the DropDownList?

Also, I'm using a DropDownList in an UpdatePanel successfully so it does work.

-Damien


Thanks for your reply, here is my Page_Load

protectedvoid Page_Load(object sender,EventArgs e)

{

TextBoxFirstName.Focus();

if (!IsPostBack)

{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

}

}


If I comment if(!Ispostback) out then the form works as it should the only problem is the that the DropDownList gets bound again after I hit the submit button and therefore the the ID returned by the DropDownList is always 1. Somebody it sitting on my brain and I can't figure this out. Any ideas? Thanks, Newbie

protectedvoid Page_Load(object sender,EventArgs e)

{

TextBoxFirstName.Focus();

//if (!IsPostBack)

//{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

//}

}


Just fixed the problem. I overrode the OnInit event like this

protectedoverridevoid OnInit(EventArgs e)

{

base.OnInit(e);

PopulateDropDownList();

}

and added a PopulateDropDownList() method

privatevoid PopulateDropDownList()

{

//Gets the languageID for the current user.

int languageID =LanguageUtility.GetLanguageIDByTwoLetterISOLanguageName();

DropDownListCauseOfDeath.DataSource = BLL.CauseOfDeath.GetCausesOfDeathByLanguageID(languageID);

//The field in the data source which provides the item text.

DropDownListCauseOfDeath.DataTextField ="CauseOfDeath";DropDownListCauseOfDeath.DataValueField ="CauseOfDeathID";

DropDownListCauseOfDeath.DataBind();

}

Set the AutoPostBack to false

EnableViewState to true

UpdatePanel to Conditional

ScriptManager EnablePartialRendering to true

And it is all working now like a charm. DropDownList works in UpdatePanel and so do the validation controls. Thanks Microsoft.....................


Thank you for posting the solution. You just made my day!