Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Wednesday, March 28, 2012

Programatically adding UpdatePanel?

I want to programatically add an updatepanel control on a button click.

I tried adding a reference to Microsoft.Web.Atlas.dll and then creatinga System.Web.UI.UpdatePanel control but the app does not compile - withnamespace does not exist error.

Does anyone know what I should be doing or if this is possible at all?

Thanks !

you would need to import the following

Imports Microsoft.Web.UI

Then, you can create an instance of the UpdatePanel like this:

Dim UP As New UpdatePanel

Hope this works for you.


Thanks it works ... I was using System.Web.UI which was the problem
Now that I have this I'm trying to add content to the updatepanel.

I can set most of the properties, add triggers without problems.

However when I try to execute it - it gives an error saying "A ContentTemplate must be specified".

Whats the easist way to do this. I haven't found any documentation on programatically adding a contenttemplate.

Any help would be greatly appreciated!
I'm looking for the same thing myself and haven't found any answers.
You'll need to create a class that implements ITemplate, create an instance of that and set the content template property to that instance.

try this

protected

overridevoid OnInit(EventArgs e)

{

updatePanel.ContentTemplate =

newCompiledTemplateBuilder

(

newBuildTemplateMethod(CreateAtlasUpdateContent));

}

public

void CreateAtlasUpdateContent(Control container)

{

container.Controls.Add(yourcontrol);

}


dont know if this will come in handy with anyone but what i did to get around the template error was

have a class with the following:

PublicClass AjaxControl :Inherits Microsoft.Web.UI.UpdatePanelProtectedOverridesSub OnInit(ByVal eAs System.EventArgs)Me.ContentTemplate =New TemplateBuilderMyBase.OnInit(e)EndSubEndClass

Then whenever i needed to create a control that was surrounded by the update panel i would inherit this class and could just then put me.controls.add() as usual.

probs useless to you all, but works for me :)


Even if you got past the coding issues, you still can't add an UpdatePanel once InitComplete has fired (which is pretty early in the lifecycle) so you're not going to be able to accomplish what you set out to do, which I think was to add an UpdatePanel dynamically.

HTH

Has anyone been able to dynamically add an UpdatePanel to a page?

I got so far - and then I got the error:

"The UpdatePanel 'panel1'was not present when the page's InitComplete event was raised."

Is there any way around this?

Wade.

Programatically collapse a panel

With Beta 2, does anyone know how to programatically collapse a panel controlled by the CollapsiblePanel extender? When I click a button, I want to collapse a panel and change the ImageControl(image) to a different image...Here's another thread that addresses the same issue and has a code sample, although I don't know if it's right since it doesn't actually work for me.

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


I think this iswork item 5688.

this works for me

Me.CollapsiblePanelExtender1.ExpandControlID = "Panel3"

Me.CollapsiblePanelExtender1.Collapsed = False

Programmatic Button Click not causing Async Postback in FireFox

I have posted this problem in a couple of different ways in the last few weeks but that was to ask what was the cause of the problem. Through trial and error I now know the cause but not the solution.

I have an UpdatePanel with a hidden asp button within it. The problem works the same whether the button is hidden or not. If I use javascript to fire the button's onclick event a regular post back happens. If I unhide the button and manually click it an async post back happens.

This is only the case with FF2. IE7 seems to work fine.

Anyone have an idea how I can work around this?

How are you hiding the button? if you're simply setting the style to have a visibility:hidden it should work the same, if you're setting it to visible=false then it's not actually being rendered to the page and the __doPostBack() javascript you are executing (assuming you are doing it that way) is just going to do a full post back. Do you have a trigger setup for the button or do you have the ChildrenAsTriggers property set in the UpdatePanel?

Any more details you can provide will help resolve this.

Cheers,
Al


Take a look at this post and my reponses to it. The key is to set on the hidden buttonUseSubmitBehavior="false" which in FF will prevent that submission postback you are seeing.

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


Check the link

http://www.jeffzon.net/Blog/post/Refresh-the-UpdatePanel-using-JavaScript-code.aspx

programmatically created buttons click event handler not working in updatepanel

i have a hovermenuextender with Target Control - an updatepanel, PopupControl - a panel with button named edit.

when i press edit, a textbox, and a button are created programmatically and placed inside the updatepanel.

the button's click event has a handler (added programmatically) which shud replace the text in updatepanel with the text in textbox, but this is not working - here's the snippet:

1protected void OrseButton_Click(object sender, EventArgs e)2 {3 OrseUpdatePanel.ContentTemplateContainer.Controls.Add(tbox);4 OrseUpdatePanel.ContentTemplateContainer.Controls.Add(savebtn);5 savebtn.Text ="Save";6 savebtn.Click +=new EventHandler(savebtn_Click);7 }89void savebtn_Click(object sender, EventArgs e)10 {11string temp;12 temp = tbox.Text;13 OrseUpdatePanel.ContentTemplateContainer.Controls.Clear();14 OrseUpdatePanel.ContentTemplateContainer.Controls.Add(new LiteralControl(temp));1516//throw new Exception("The method or operation is not implemented.");17 }

help me on this...i m using vs 2005, asp with ajax, c#

whats hapening is ur manipulating ur button and events at runtime, so when the page postback, the buton info and event is lost, what u need to to is save the whole thing to a viewstate, then on page call back u must recall this viewstate and reassign it to the button.

savebtn.Text ="Save";
savebtn.Click +=new EventHandler(savebtn_Click);

ViewsState["btn"] = savebtn;

On ur callback

savebtn = (button)ViewsState["btn"]

Hope this helps


i placed :

savebtn = (button)ViewsState["btn"]

in savebtn_click method.

now when i run it, it gives error serializing value 'system.web.ui.webcontrols.button' of type 'system.web.ui.webcontrols.button'


ok, on each callback recreate the event for ur button, coz when creating event at runtime, and when there'sa postback or callback, the event is lost, so have to recreate it and Once created ASP.Net directly rebind it.


can i have some example code...i wanna make sure i got u completely.

Programmatically created Submit button on UpdatePanel want fire without The UpdatePanel be

I have programmatically created some controls(labels, buttons) that make up and object in several rows of a table on an UpdatePanel. On the initial load of the page, I create all the objects(controls). Then I click one of the buttons to do a partialrendering update of some the controls in the UpdatePanel. The button click causes a post back which I throught was good. The problem is that if i do not refesh the entire set of controls on the UpdatePanel first, the button click want fire and I can't firgure out why.

Here is some of the code:

<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"AsyncPostBackTimeout="36000"/><asp:UpdatePanelID="UpdatePanel2"runat="server"ChildrenAsTriggers="false"UpdateMode="Conditional"><ContentTemplate><asp:TableID="Table1"runat="server"></asp:Table><asp:UpdateProgressID="UpdateProgress"runat="server"AssociatedUpdatePanelID="UpdatePanel2"><ProgressTemplate>

Processing Service Request .........

</ProgressTemplate></asp:UpdateProgress></ContentTemplate></asp:UpdatePanel>

protectedvoid btnSubmit_Click(object sender,EventArgs e)

{

RefreshStatus(); --> Causes controls to be built on UpdatePanel.

}

protectedvoid Page_Load(object sender,EventArgs e)

}

if (!IsPostBack)

{

}

else

{

<-- If I do a"RefreshStatus();"here, all works fine but the entire set of controls on the UpdatePane is re-Built. Not what I want.

}

Button Click:

void ChangeStatus_Click(object sender,EventArgs e)

{

Button ChangeStatus = (Button)sender;

----- Update subset of controls on UpdatePanel here -------

}

Since there is no ReFreshStatus() during the postback the button wantfire and nothing happens. I am puzzel by this.

Any Ideas?

Thanks

I forgot mention the each button is built with a AsyncPostBack trigger, ie:

// Add Updatepanel Triggers for the buttonAsyncPostBackTrigger trigForBtns;

trigForBtns =

newAsyncPostBackTrigger();

trigForBtns.ControlID = ChangeStatus.ID;

trigForBtns.EventName =

"Click";

Thanks again, I really need some help with this.


I just wanted to mention that I solved this problem byImplementing Ajax incremental asynochronous updating of controls on the web page.


Thats niceSmile

Can you post some code details here ?

Monday, March 26, 2012

Progress bar appear when submiting form

I have a contact us form that sends an email.

I want to use an update panel which allows me to do the following:

When the user clicks the send button, form dissapear and progress bar is show for a couple seconds and then notification to the user if email sent ok or not.

I have implemented this using updatepanel and updateprogress but 99% of the time the updateprogress is not displayed because the command is carried out so quick. I would like the progress bar be displayed and give the user the feel of the email being sent. I have the form in a standard panel. How can i make sure the form disappear and updateprogress is displayed?

I have looked at using the updatepanelanimator but it seems difficult to use and think i can do what i want to do without it, correct?

Appreciate any help.

You could approach this a number of ways.. here is probably the quickest and dirtiest way but I don't recommend it:

Add:

System.Threading.

Thread.Sleep(2000);

To your server side processing, this will block the current thread for a specific number of milliseconds forcing the browser and UpdateProgress to wait for the response. Please don't do this. :)

A better way to do this would be to use an animation sequence to give the user the visual feedback that something has taken place, in this case that an email has been sent. The ASP.NET Ajax Animation Toolkit works excellent for this because you can specify the duration for which animations will run... so even if your UpdateProgress and UpdatePanel have completed processing, you could still have an animation still playing before the user moves on to a new action.

Try the animation framework, it's quick to pickup and has some very nice tutorials:http://ajax.asp.net/ajaxtoolkit/Walkthrough/UsingAnimations.aspx

Cheers,
Al

Progress template not showing

I got an updatepanle, an updateprogress , a label inside the update panel, and a button outside the updatepanel, what i wanna do is just simple, delay 5 sec before showing the label and at the same time showing the "loading..." before it complete. Problem occured when i put the button outiside of the updatepanel and it did not show the "loading.." and after 5 sec the label will shown , but everything works fine when i put the button in the updatepanel...I did set the button as trigger.

so may i know where is the problem ?

Thanx~

Hi giox,

Posting the code of your page would help us in locating the eventual problem.

Would you be so kind to use the Source Code button of the rich editor to insert code? TNX!

Kind regards,
Wim


i dont believe you need to set the button as a trigger if its in the update panel, also, have you tried setting the update progress "DisplayAfter" property to "0"?


Wim,

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lbl1" runat="server" Style="left: 48px; top: 0px" Text="Label" Width="352px"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
</div>

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0">
<ProgressTemplate>
loading..
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</form>

VB code :

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Threading.Thread.Sleep(3000)
Me.lbl1.Text = "abc"
End Sub

Thanx~


Lee Brennan:

i dont believe you need to set the button as a trigger if its in the update panel, also, have you tried setting the update progress "DisplayAfter" property to "0"?

The problem occured when the button is outside the update panel..

I tried to set "DisplayAfter" property to "0", but it still not working. thanx anyway.


The documentation is the problem on this one. If you look at the AssocitatedUpdatePanelID attribute, it states "You can set theAssociatedUpdatePanelID property to controls in the same naming container, a parent naming container, or the page."

What exactly that means is certainly not clear, because it does not work if it is used as a sibling of the UpdatePanel. (and you would think that that's what "in the same naming container" means)

If you delete the AssociatedUpdatePanelID completely, your example will work.

Of if you move the UpdateProgress "as is" inside the UpdatePanel, it will also work.


If want to show the UpdateProgress for a control which is outside the UpdatePanel you have to manually hook the initializeRequest and endRequest of PageRequestManager to show the UpdateProgress, like the following:

<script type="text/javascript"> var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_initializeRequest(initializeRequest); prm.add_endRequest(endRequest); var _postBackElement; function initializeRequest(sender, e) { if (prm.get_isInAsyncPostBack()) { e.set_cancel(true); } _postBackElement = e.get_postBackElement(); if (_postBackElement.id.indexOf('Button1') > -1) { $get('UpdateProgress1').style.display = 'block'; } } function endRequest(sender, e) { if (_postBackElement.id.indexOf('Button1') > -1) { $get('UpdateProgress1').style.display = 'none'; } }</script>

While I use the technique above as well for most projects, it is not necessary in this example. Simply eliminating the AssociatedUpdatePanelID attribute on the ProgressPanel will allow the example to work. That occurs because Button1 is also defined as a trigger for the panel. What was confusing is why it doesn't work with the attribute set because that is not clear from the documentation for the AssociatedUpdatePanelID attribute.

When reading the documentation for the UpdateProgress, none the scenarios described include the way the example was initially written. Only when the attribute is deleted does the following statement (bold type) apply:

"If you do not set theAssociatedUpdatePanelID property, theUpdateProgress control displays progress for any asynchronous postback that originates from inside anyUpdatePanelor for controls that are triggers for panels."


wrayx1:

While I use the technique above as well for most projects, it is not necessary in this example. Simply eliminating the AssociatedUpdatePanelID attribute on the ProgressPanel will allow the example to work. That occurs because Button1 is also defined as a trigger for the panel. What was confusing is why it doesn't work with the attribute set because that is not clear from the documentation for the AssociatedUpdatePanelID attribute.

It works when eliminating the AssociatedUpdatePanelID ...Thanx..the problem has solved, thanx to those who helping to solve this problem as well.

Property value disappear on click with user control

Hi,

I have a user control which require input text boxes and a caclulate button. When I hit the recalculate button, lblMonth becomes blanks. Please see the code below and guide how to keep the lblMonth the value of lblMonth

============
<asp:UpdatePanel ID="upPanelSales" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblMonth" runat="server" Font-Bold="true" ForeColor="white" CssClass="heading" />
-- some text box controls
<asp:Button ID="btnReCalc" runat="server" Text="Recalc." CommandName="Calculate" CommandArgument="ReCalc" OnCommand="Calculate" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnReCalc" EventName="Command" />
</Triggers>
</asp:UpdatePanel
Code Behind
Private _MonthNameAs String

Public Property MonthName()As String
Get
Return _MonthName
End Get
Set(ByVal valueAs String)
_MonthName = value
End Set
End Property

Protected Sub Page_PreRender(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.PreRender
Me.lblMonth.Text = _MonthName
End Sub

Protected Sub Calculate(ByVal senderAs Object,ByVal eAs CommandEventArgs)
If e.CommandName ="Calculate"Then
Select Case e.CommandArgument
Case"ReCalc"
ReCalculate()
End Select
End If
End Sub

Main Page
=========

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
<Sales:Input ID="uc" runat="server" />
Code Behind

Sub Page_Load
uc.MonthName = Month1
End Sub

you probably want to do this in your main page code behind so it only gets set when the page loads the first time

Sub Page_Load

if not Page.IsPostBack Then
uc.MonthName = Month1
end if
End Sub


My main page contains 4 link button controls called Qtr1, Qtr2, Qtr3, Qtr4 and I want to change the month value based on user clicking on quarter links? The real problem is due to submit button inside the user control and partial page refresh has applied on this user control.


so you solved it? or you're still asking?

if those 4 links are outside of the updatepanel they will trigger a full post back and the data inside the update panel contents will be treated no differently than if they weren't inside an updatepanel.

if you click the the linkbutton inside the updatepanel the only thing that will happen is the data within the updatepanel will postback and the associated button event will fire. Only data within the updatepanel will post back to the server though. Data outside of the updatepanel will still appear to the server as the same data regardless of change on the client side...

Saturday, March 24, 2012

Pulling hair out! Cannot get GridView & Search Button to work with Update Panel

I don't know what else to do. As far as I know, my web.config is set up fine. I get no errors as to the ASP.NET AJAX controls and I feel I have tried everything I know, which isn't much yet about UpdatePanels but there doesn't seem to be that much to know after reading

Here's my code below. When I click the search button, I still am getting a full page postback:

<formid="Form1"runat="server"method="post">

<asp:scriptmanagerid="ScriptManager1"enablepartialrendering="true"runat="server"/>

...more code and then

<tdclass="narrowTableWrapperCell"colspan="8"align="left">

<asp:updatepanelid="gvSearchResultsUpdatePanel"runat="server"updatemode="always">

<contenttemplate>

<asp:updateprogressid="UpdateProgressSearchResults"runat="server">

<progresstemplate>

Working......

</progresstemplate>

</asp:updateprogress>

<asp:buttonid="Search"runat="server"onclick="Search_Click"usesubmitbehavior="false"width="113px"/>

<asp:gridviewid="SearchResults"runat="server"onpageindexchanging="SearchResults_PageIndexChanging"onrowcreated="SearchResults_OnRowCreated"

onsorting="SearchResults_Sorting">

<columns>

<asp:templatefielditemstyle-horizontalalign="left">

<headertemplate>

<asp:checkboxid="cbSelectAll"runat="server"textalign="left"/>

</headertemplate>

<itemtemplate>

<asp:checkboxid="cbRow"runat="server"/>

<asp:hyperlinkid="hyName"runat="server"navigateurl='<%# FormatUrl(Eval("MyID"))%>'text='<%# Eval("FullName")%>'/>

</itemtemplate>

</asp:templatefield>

<asp:boundfielddatafield="Phone"headertext="Phone"htmlencode="False"itemstyle-horizontalalign="left"readonly="True"sortexpression="Phone"/>

<asp:boundfielddatafield="HomePhone"headertext="Other Phone"htmlencode="False"itemstyle-horizontalalign="left"readonly="True"sortexpression="HomePhone"/>

<asp:boundfielddatafield="Email"headertext="Email"htmlencode="False"itemstyle-horizontalalign="left"readonly="True"sortexpression="Email"/>

<asp:boundfielddatafield="AlternateEmail"headertext="Alt Email"htmlencode="False"itemstyle-horizontalalign="left"readonly="True"sortexpression="AlternateEmail"/>

<asp:boundfielddatafield="PrimaryAddress"headertext="Primary Address"htmlencode="False"itemstyle-horizontalalign="left"readonly="True"sortexpression="PrimaryAddress"/>

<asp:boundfielddatafield="ShippingAddress"headertext="Shipping Address"htmlencode="False"itemstyle-horizontalalign="left"readonly="True"sortexpression="ShippingAddress"/>

</columns>

</asp:gridview>

</contenttemplate>

</asp:updatepanel>

</td>

...rest of aspx

My Webconfig:

<?xmlversion="1.0"?>

<configuration>

<!-- ASP.NET AJAX Settings | Do not remove-->

<sectionGroupname="system.web.extensions"type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

<sectionGroupname="scripting"type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

<sectionname="scriptResourceHandler"type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="MachineToApplication"/>

<sectionGroupname="webServices"type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

<sectionname="jsonSerialization"type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="Everywhere" />

<sectionname="profileService"type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="MachineToApplication" />

<sectionname="authenticationService"type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="MachineToApplication" />

</sectionGroup>

</sectionGroup>

</sectionGroup>

<!-- End ASP.NET AJAX Settings-->

</configSections>

<system.web>

<!-- ASP.NET AJAX Settings | Do not remove-->

<pages>

<controls>

<addtagPrefix="asp"namespace="System.Web.UI"assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addtagPrefix="asp"namespace="System.Web.UI.Controls"assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addtagPrefix="ajaxToolkit"namespace="AjaxControlToolkit"assembly="AjaxControlToolkit"/>

<addtagPrefix="iu"tagName="Footer"src="~/Components/Footer.ascx" />

<addtagPrefix="iu"tagName="Header"src="~/Components/header.ascx" />

<addtagPrefix="iu"tagName="Navbar"src="~/navbar.ascx" />

</controls>

</pages>

<compilationdebug="true">

<assemblies>

<addassembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</assemblies>

</compilation>

<!-- End ASP.NET AJAX Settings-->

<httpHandlers>

<!-- ASP.NET AJAX Settings | Do not remove-->

<removeverb="*"path="*.asmx"/>

<addverb="*"path="*.asmx"validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addverb="*"path="*_AppService.axd"validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addverb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false"/>

<!-- End ASP.NET AJAX Settings-->

<addpath="ChartAxd.axd"verb="*"type="Dundas.Charting.WebControl.ChartHttpHandler"validate="false" />

</httpHandlers>

<!-- ASP.NET AJAX Settings | Do not remove-->

<httpModules>

<addname="ScriptModule"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</httpModules>

<!-- End ASP.NET AJAX Settings-->

<xhtmlConformancemode="Legacy"/>

</system.web>

<!-- ASP.NET AJAX Settings | Do not remove-->

<system.web.extensions>

<scripting>

<webServices>

<!-- Uncomment this line to customize maxJsonLength and add a custom converter-->

<!--

<jsonSerialization maxJsonLength="500">

<converters>

<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>

</converters>

</jsonSerialization>

-->

<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate.-->

<!--

<authenticationService enabled="true" requireSSL = "true|false"/>

-->

<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved

and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and

writeAccessProperties attributes.-->

<!--

<profileService enabled="true"

readAccessProperties="propertyname1,propertyname2"

writeAccessProperties="propertyname1,propertyname2" />

-->

</webServices>

<!--

<scriptResourceHandler enableCompression="true" enableCaching="true" />

-->

</scripting>

</system.web.extensions>

<!-- End ASP.NET AJAX Settings-->

</configuration>

You forgot to add triggers. See the other post you sumited on this subject. I gave you an example code for you to use.

Question about DragPanel implementation

I'm building a dragbuttonextender which purpose is to extend button control so that it can be dragged and dropped. In AjaxControlToolkit's implementation of DragPanel in FloatingBehavior.js there is a functioncheckCanDrag which looks like:

this.checkCanDrag = function(element) {
var undraggableTagNames = ["input", "button", "select", "textarea", "label"];
var tagName = element.tagName;
if ((tagName.toLowerCase() == "a") && (element.href != null) && (element.href.length > 0)) {
return false;
}
if (Array.indexOf(undraggableTagNames, tagName.toLowerCase()) > -1) {
return false;
}
return true;
}

My question is:Why are buttons and input controls undraggable?

I wrote my extender (which extends ASP.NET Button controls) and I can drag&drop buttons. The problem is that when drag&drop ends a full postback occurs and position of the button is restored to its original location. When I use my extender (which is currently almost identical to AjaxControlToolkit's DragPanelExtender except checkCanDrag function) to extend ASP.NET Panel control then everything works fine and panels are placed where I dropped them. When I put buttons in a panel and attach my extender to this panel, again everything works fine. So, why can't buttons be extended just like panels are extended?

Anybody?

question about the callback feature and scriptmanager

Hi,my application will have a textfield and a button (html control) and when the button is clicked, it will pass the textfield.value by calling a javascript function to the server side function and do something such as find the data in a database, after that it will return the result back to html page.

my question is, as far as I know I can use callback feature to do this, becuase what i need to do is register a page in the behind code. so the js function can call the registed function. However, as I know if use the scriptmanager and create a web serivce page with setting the class or specific methods as [scriptservice] attribute, then the js function can also call the code-behind function. therefore I wonder what is the different between those two feature. Hope someone can explain to me.

Ok, so you are using Callbacks instead of postbacks by using ICallBackHandler? Then you are also using MS AJAX? with ScriptManager?

You should only use one kind of AJAX. If you use only MS AJAX you won't have to use javascript to update your controls.

Wednesday, March 21, 2012

Question re default button inside an update panel not working

I have a page containing an update panel. Inside the update panel are two user controls: one that displays messages, and one that allows message capture.
The message-capture control looks like this:


<asp:Panel ID="PanelChatSay" runat="server" DefaultButton="ButtonSay" >
<asp:TextBox ID="TextBoxChat" runat="server" Width="90%"/>
<asp:Button ID="ButtonSay" runat="server" Text="Say" OnClick="ButtonSay_Click" />
</asp:Panel
I want the enter key to submit as if the "Say" button had been pressed. Yet when focus is in the textbox and I hit enter, nothing happens. All that seems to happen is that the text box loses focus.

Any ideas on how to fix this?

Hi,

I tried your code, the page was successfully submitted when I hit enter.

If it doesn't work for you, you may use the following script to force it.

<asp:TextBox ID="TextBox1" runat="server" Width="90%"onkeypress="if(event.keyCode == 13)document.getElementById('Button1').click();"/>

Hope this helps.


Hi AnthonySteetle,

I have read your question carefully and got a little confused. In your thread, I think you have two questions:

AnthonySteele:


I want the enter key to submit as if the "Say" button had been pressed.

My Sample:

<%@. 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"> protected void ButtonSay_Click(object sender, EventArgs e) { this.Label1.Text = DateTime.Now.ToString(); } protected void TextBoxChat_TextChanged(object sender, EventArgs e) { this.Label1.Text = DateTime.Now.ToString(); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Panel ID="PanelChatSay" runat="server" DefaultButton="ButtonSay"> <asp:TextBox ID="TextBoxChat" runat="server" Width="90%" onkeyup="updateDate()" AutoPostBack="false" OnTextChanged="TextBoxChat_TextChanged"/> <asp:Button ID="ButtonSay" runat="server" Text="Say" OnClick="ButtonSay_Click"/> </asp:Panel> </ContentTemplate> </asp:UpdatePanel> <script type="text/javascript" language="javascript"> function updateDate(){ __doPostBack("<%=TextBoxChat.ClientID%>",''); } </script> </form></body></html>

AnthonySteele:


Yet when focus is in the textbox and I hit enter, nothing happens

Please confirm if your submit button is focused when the textbox is clicked. My sample seems it works fine.

Hope this helps. If I misunderstood you, please let me know.


Thank, Raymond. That does the general trick. I have it working as follows:

* remove the defaultButton declaration from the panel.
* Add the following to the page load:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string enterScript = "if(event.keyCode == 13) document.getElementById('" + ButtonSay.ClientID + "').click();";
TextBoxChat.Attributes.Add("onclick", enterScript);
}
}

Now all I need to do is put input focus back in the text box after postback.

Question regarding error code

I added a script to the scriptmanager that cancels a request (a button click) if there current outstanding async request. Below the questions is the javascript that is being used

Questions:
1. I got a random 12004 error as a message box. Its only happened once, and I am not sure how to track it as it was "an unknown error".

2. Is there a way to tell if the way to tell if the the button caused the postback currently being processed, and the control requesting one?

3. In the javascript (taken fromhttp://www.asp.net/AJAX/Documentation/Live/tutorials/CancelAsyncPostback.aspx) there is this symbol: !== what does this do?

Sys.Application.add_load(ApplicationLoadHandler)
function ApplicationLoadHandler(sender, args)
{
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
}


function CheckStatus(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm.get_isInAsyncPostBack() & args.get_postBackElement().id == 'Button1')
{
args.set_cancel(true);
}

}

if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

!== and === are strictly typed comparisons, instead of the dynamic typing that JavaScript normally uses. For example, 3 == "3" is true, but 3 === "3" is false.

For checking the sender against current request, I'd suggest making sure the button is disabled when a request is made instead. That way you don't even have to worry about getting the same control that you're processing for as a new request (which I assume is what you're trying to handle with the check).


The issue is that javascript such as: document.getElementById('Button1').click() can still fire even if the button is disabled.