Showing posts with label register. Show all posts
Showing posts with label register. Show all posts

Wednesday, March 28, 2012

Extender with inclusion of JS files in particular order.

Right now I'm working on an extender that needs to include numerous .js files I'd like to register for inclusion on a page.

I've added:

[assembly: System.Web.UI.

WebResource("first.js","text/javascript")]

[assembly: System.Web.UI.

WebResource("second.js","text/javascript")]

In the root of the Extender.cs class... as well as...

[ClientScriptResource("first","first.js")]

[

ClientScriptResource("second","second.js")]

Seems like if it were just one of the scripts by itslef it seems to do an ok job... but for scrips that rely on eachother, the straight up fail. Is the extender model only destined to have one script file period? If not, are scripts loaded and rendered in the order I add the ClientScriptResource attributes?

Is there another way I SHOULD be doing this? The .js files are being bundled in as Embedded Resource which is desired functionality, however the js variables that are now supposed to be present at the document scope simply arent. Somethign strange about which scripts are being loaded, or what order they are being loaded in.

Any advice would be greatly appreciated. Thanks

ClientScriptResource also takes named parameters, of which there is a LoadOrder and you can specify a load order. I found this to be the solution to my problem. Couple small little hurdles and I should be on my way.

Wednesday, March 21, 2012

Error:Extender controls may not be registered before PreRender

I have a user control in which I use an autocomplete extender for a textbox.in code behind I register a script in OnPreRender method.I used this user control in 2 pages.In one of them it works well but in another page with the same structure I get this error "Extender controls may not be registered before PreRender".

Does anybody know what it is?

here is the user controls code:

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="AddSignaturePanel.ascx.cs"Inherits="AddSignaturePanel" %>

<%@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Preview"Namespace="Microsoft.Web.Preview.UI.Controls"TagPrefix="asp" %>

<

asp:ButtonID="btnDivOpener"CssClass="Button"runat="server"meta:resourcekey="btnDivOpenerResource"/>

<divdir="rtl"id='PersonDiv'style=' visibility:hidden; border:1px solid #000080; position: absolute; width: 250px;background-color: #e8f1d6;'><tablewidth='100%'><tr><tdclass="TwoColTDLabelDiv"><asp:LabelCssClass="TwoColLabel"ID="lblUserName"runat="server"meta:resourcekey="lblUserNameResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxCssClass="SigPanelTextBox"ID="txtUserName"runat="server"meta:resourcekey="txtUserNameResource1"></asp:TextBox><asp:AutoCompleteExtenderID="NameAutoComplete"Visible="true"runat="server"TargetControlID="txtUserName"MinimumPrefixLength="1"ServiceMethod="GetUserByUsername"ServicePath="../../Common/Services/PersonSearchSRVC.asmx"/></td></tr><tr><tdclass="TwoColTDLabelDiv"><asp:LabelCssClass="TwoColLabel"ID="lblSignatureKey"runat="server"meta:resourcekey="lblSignatureKeyResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxCssClass="SigPanelTextBox"ID="txtSignatureKey"runat="server"meta:resourcekey="txtSignatureKeyResource1"></asp:TextBox></td></tr><tr><tdclass="TwoColTDLabelDiv"><asp:LabelID="lblCondition"runat="server"CssClass="TwoColLabel"meta:resourcekey="lblConditionResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxID="txtCondition"runat="server"CssClass="SigPanelTextBox"meta:resourcekey="txtConditionResource1"></asp:TextBox></td></tr><tr><tdclass="TwoColTDLabelDiv"><asp:LabelID="lblComment"runat="server"CssClass="TwoColLabel"meta:resourcekey="lblCommentResource"></asp:Label></td><tdclass="TwoColTDSeperatorDiv"></td><tdclass="TwoColTDControlDiv"><asp:TextBoxID="txaComment"runat="server"CssClass="SigPanelTextBox"TextMode="MultiLine"meta:resourcekey="txaCommentResource1"></asp:TextBox></td></tr><tr><tdclass="DivButtonTDButtons"colspan="3"><asp:ButtonCssClass="Button"ID="btnSubmit"runat="server"meta:resourcekey="btnSubmitResource"/><asp:ButtonCssClass="Button"ID="btnUnSubmit"runat="server"meta:resourcekey="btnUnSubmitResource"/><asp:ButtonCssClass="Button"ID="btnCancel"runat="server"meta:resourcekey="btnCancelResource"/> </td></tr></table></div>

and in code behind I have this:

public

partialclassAddSignaturePanel :ModuleBase

{

#region

private membersprivateIEntity _entity;

#endregion

#region

Public PropertiespublicIEntity Entity

{

set

{

base.ViewState["Type"] = ((IEntity)value).Type ;base.ViewState["Key"] = ((IEntity)value).Key;

}

//get//{// return (IEntity)base.ViewState["Type&Key"];//}

}

#endregion

#region

Delegates and EventHandlerspubliceventAddSignatureEventHandler SubmitEvent;publiceventAddSignatureEventHandler UnSubmitEvent;publicvirtualvoid OnSubmit(object sender,EventArgs e)

{

string userName = txtUserName.Text;string signatureKey = txtSignatureKey.Text;string comment = txaComment.Text;try

{

User user =SecurityService.Instance.GetUser(userName);EntityReference er= Faraconesh.ApplicationFramework.Core.DataAccess.EntityReferenceDAS.Instance.GetEntityReference(base.ViewState["Key"].ToString(),base.ViewState["Type"].ToString());Signature sign =SignatureService.Instance.AddSignature(user.Person, signatureKey, er,"", comment);AddSignatureEventArgs ase =newAddSignatureEventArgs();

ase.Signature = sign;

if (sign !=null && SubmitEvent !=null)

{

SubmitEvent(

this, ase);

}

}

catch (Exception ex)

{

thrownewException(ex.Message);

}

}

publicvirtualvoid OnUnSubmit(object sender,EventArgs e)

{

string userName = txtUserName.Text;string signatureKey = txtSignatureKey.Text;string comment = txaComment.Text;User user =SecurityService.Instance.GetUser(userName);Signature sign =SignatureService.Instance.AddSignature(user.Person, signatureKey, (IEntity)user,"", comment);AddSignatureEventArgs ase =newAddSignatureEventArgs();

ase.Signature = sign;

if (sign !=null && UnSubmitEvent !=null)

{

UnSubmitEvent(

this, ase);

}

}

#endregion

#region

overridden methodsprotectedvoid Page_Load(object sender,EventArgs e)

{

btnUnSubmit.Click +=

newEventHandler(OnUnSubmit);

btnSubmit.Click +=

newEventHandler(OnSubmit);

btnDivOpener.Attributes.Add(

"onClick","openSearchDiv" +this.ClientID +"();return false;");

btnCancel.Attributes.Add(

"onClick","closeSearchDiv" +this.ClientID +"();return false;");

}

protectedoverridevoid OnPreRender(EventArgs e)

{

base.OnPreRender(e);if (!Page.ClientScript.IsClientScriptBlockRegistered("DivOpener" +this.ClientID))

{

StringBuilder strBuilder =newStringBuilder();

strBuilder.Append(

"<script type='text/javascript'>");

strBuilder.Append(

"function openSearchDiv" +this.ClientID +"(){");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.visibility='visible';");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.top= screen.availWidth/2 -250;");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.left=screen.availHeight/2;");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"}");

strBuilder.Append(

"function closeSearchDiv" +this.ClientID +"(){");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

" document.getElementById('PersonDiv').style.visibility='hidden';");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"}");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"</script>");

strBuilder.Append(

Environment.NewLine);string script = strBuilder.ToString();

Page.ClientScript.RegisterClientScriptBlock(

typeof(AddSignaturePanel),"DivOpener" +this.ClientID, script);

}

if (!Page.ClientScript.IsStartupScriptRegistered("ShowModalDialog" +this.ClientID))

{

StringBuilder strBuilder =newStringBuilder();

strBuilder.Append(

"<script type='text/javascript'>");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"var PersonPopup"+this.ClientID+"= new modalDialog('PersonDiv',50,50);");

strBuilder.Append(

Environment.NewLine);

strBuilder.Append(

"</script>");

strBuilder.Append(

Environment.NewLine);string script=strBuilder.ToString();

Page.ClientScript.RegisterStartupScript(

typeof(AddSignaturePanel),"ShowModalDialog" +this.ClientID, script);

}

}

#endregion

publicUser GetUser()

{

string userName=txtUserName.Text;string signatureKey = txtSignatureKey.Text;string comment=txaComment.Text;User user=SecurityService.Instance.GetUser(userName);return user;

}

}

I found the solution.just in the aspx file in which I used the user control I'd overridden onprerender method but didnt call tha base prerender for it.Wink

Hi...

If u want to get ride of this error then

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

if u r using usercontrol then paste this in ur .aspx page...