Showing posts with label click. Show all posts
Showing posts with label click. 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.

Monday, March 26, 2012

Programmically create ModalPopup

I have load data and show it in DataGridView control.
What can I do to archieve the following criteria:

When user click on a specific cell - it will bring up detail records in modalPopup extender control?

See forum posthttp://forums.asp.net/thread/1613190.aspx. It talks about PopupControl but you could use the same principle here.

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

push message to user

Hi, I would like to know how do i push a message to multiple users in asp.net atlas?

I would like to enter a message then click send and it would display on multiple users computers in a box that would appear within a webpage.

This would be used to alert users of network issues.

thanks

Kunal

You could use theTimer control:


thanks, is there any other controls or ways to push the content, i have heard of ajax comet.


I'm afraid that you cann't do this in another way, The Ajax isn't a kind of "Server push" technology.

Wednesday, March 21, 2012

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.