Showing posts with label inside. Show all posts
Showing posts with label inside. Show all posts

Wednesday, March 28, 2012

Programmatically adding multi DragPanelExtenders?

Hi;

First of all what I need is to have more then one dragable panels inside my page. DragAndDrop em, record their locations to the DB

I'm using this script that I found in asp.net forum to find the location:

<scripttype="text/javascript">
Sys.Application.add_load(dragSetup);
function dragSetup() {
var dragPanel = $find('dragPanelBehavior1');
dragPanel.add_propertyChanged(locationUpdatedHandler);// the handler would get the name of the property from the event args and if it is 'location' then do the right thing.
returnfalse; }

function locationUpdatedHandler(sender, eventargs) {
if(eventargs.get_propertyName() =='location') {
var dragPanel = $find('dragPanelBehavior1');
var label = $get('dragPanelLocation');
var loc = dragPanel.get_location()
label.innerHTML = loc;}
}
</script>

However because of this script I have in the webusercontrol whenever I add my second webusercontrol it returns an error because they both aims the same panel's dragPanelBehavior1.

I couldn't solve this problem, any help would be preciated.

Again what I actually need is more then one dragable panels containig a webusercontrol and that I can find the location.

Thanks in advance

Hi Kaan,

First, DragPanelExtender's BehavirID should be uniquej though they are in different WebUserControls which are located in the same page.

Secondly, in your situation, I think you should remove out the Sys.Application.add_load(dragSetup) and its related functions from WebUserControls to the page.

To get or set the Panel's location , we can also use

//get

var el = $find('DragPanelBID').get_element();
var newLocation = $common.getLocation(el);

//set

var finalLocation = new Sys.UI.Point(x,y);
$find('DragPanelBID').set_location(finalLocation);

Hope this help.

Best regards,

Jonathan

Monday, March 26, 2012

Programmatically setting EnablePartialRendering to false from master page

Hi,

I have a master page which has its content area wrapped inside an updatepanel. To facilitate debugging, I'ld like to "disable" the updatepanel when the request URL contains ?debug=true.

I understood that to disable the updatepanel, setting EnablePartialRendering to false should do the trick. This can only be done from PreInit.

The problem I'm facing now is that:

The master page doesn't have an OnPreInit method to overrideWhen I override the OnPreInit in the content page, there's no ScriptManager available (via ScriptManager.GetCurrent(Page)), since the ScriptManager is defined in the master page.

Any idea on how I can solve this without having to create 2 master pages (with & without the UpdatePanel) and dynamically switching between both?

Wouter

Locate the WebpartManger in masterpage by

this.MasterPage.FindControl("yourwebpartmangerid");


Thanks for the hint. I was able to locate the scriptmanager in this way and disable the partial rendering.

However, a new problem arose after I did all this. The page showed two assert popup boxes:

"Assertion Failed: Could not resolve reference to object named "_PageRequestManager" for "dataContext" property on object of type "Sys.Binding""

"Assertion Failed: No data context available for binding with ID "" and dataPath "inPostBack" on object of type "Sys.UI.Control""

I've tracked this down to the UpdateProgress control, which still renders xml-script while EnablePartialRendering is false (see also http://forums.asp.net/thread/1250774.aspx)

I'm now trying to programmatically remove or disable the UpgradeProgress control as well, but had no luck so far :(


hello.

ah, i remember that...well, in fact, the class has 2 bugs:

1. the 1st is that it renders xml-script without checking for its visible property
2. the 2nd is that the interface is implemented explicitly without any delegation to a protected virtual method (this would let you easilly fix this).

so, your best option is to write your own updateprogress control.

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.

Saturday, March 24, 2012

put an AutoPostBack=true control inside a updatepanel?

Hi, All:

Just upgrade to AJAX. Everything works greate. Maybe this is a simple question.

I have a gridview which is inside in a updatepanel. then I have an dropdownlist inside a ItemTemplate of my GridView and this the autopostback attribute of this ddl is set to true. I have a onselectedindexchanged event to do something and refresh the gridview (old fashion way). Does this autopostback= true will refresh the whole page ( I have other controls on this page except theis gridview). I tried and It looks like it just refresh the gridview only. Am I right? If I set the autopostback=false, then nothing happened. I can not put this ddl into Triggers since it is an control in the itemtemplate of the gridview

Another question, with this ddl index changed event, I want to change partial of the gridview only, say show or hide a label in another itemtemplate, what should I do? put the updatepanel inside the itemtemplate??

Thanks

-rockdale

Hello rockdale,

Question: *** I tried and It looks like it just refresh the gridview only. Am I right? ***
YES, since it's inside the UpdatePanel. Leave your AutoPostBack=True.

Question: *** I want to change partial of the gridview only, say show or hide a label in another itemtemplate ***
Step1: *** onselectedindexchanged event to do something and refresh the gridview (old fashion way). ***

Sample:
<asp:gridview id="gridview1"... >
<columns>
<asp:templatefield>
<itemtemplate>
<asp:Label id="lblName" Text="John Smith" runat="server" />
</itemtemplate>
...

At Step1, you can hide or show part of your gridview.

dim ctrl as control
ctrl = controlfinder.fincontrol(me.gridview1, "lblName")
if not ctrl is nothing then
ctype(ctrl, label).visible = true or false
end if

WS


Question about DropDownList behavior inside an UpdatePanel

Hi,

I have an application that has two DropDownLists on a page. The first is just a plain ASP DropDownList; the second is an ASP DropDownList inside an UpdatePanel. The page also contains a label inside a second UpdatePanel.

When the item in the first DropDownList is changed, the second DropDownList is populated. When the item in the second DropDownList is changed, the Label's text is changed.

I have noticed that when the first DropDownList changes, the second DropDownList "flickers" as it populates. When I select a value in the second list, the label updates as it should, but the second DropDownList again flickers, as if it is also being refreshed. Both UpdatePanels have UpdateMode="conditional" set.

My question is whether this is normal behavior on the second DropDownList, since it is inside an UpdatePanel, or do I have something set wrong? It's a minor issue, but kind of annoying since I would not expect to see any kind of refresh when changing a value in the second DropDownList.

I have included a simple example which shows what I'm talking about. Thanks as always for your help!

<%@dotnet.itags.org.PageLanguage="vb"AutoEventWireup="false"CodeBehind="Default.aspx.vb"Inherits="DropDownTest._Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

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

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

<div>

<ASP:DROPDOWNLISTid="DropDownList1"autopostback="true"runat="server"width="110px"></ASP:DROPDOWNLIST>

<br/><br/><br/><br/><br/><br/>

<ASP:UPDATEPANELid="UpdatePanel1"runat="server"updatemode="conditional">

<CONTENTTEMPLATE>

<ASP:DROPDOWNLISTid="DropDownList2"autopostback="true"runat="server"width="110px"></ASP:DROPDOWNLIST>

</CONTENTTEMPLATE>

<TRIGGERS>

<ASP:ASYNCPOSTBACKTRIGGERcontrolid="DropDownList1"eventname="SelectedIndexChanged"/>

</TRIGGERS>

</ASP:UPDATEPANEL>

<br/><br/><br/><br/><br/><br/>

<ASP:UPDATEPANELid="UpdatePanel2"runat="server"updatemode="conditional">

<CONTENTTEMPLATE>

<ASP:LABELid="Label1"runat="server"text="Label"></ASP:LABEL>

</CONTENTTEMPLATE>

<TRIGGERS>

<ASP:ASYNCPOSTBACKTRIGGERcontrolid="DropDownList2"eventname="SelectedIndexChanged"/>

</TRIGGERS>

</ASP:UPDATEPANEL>

</div>

</form>

</body>

</html>

PartialPublicClass _Default

Inherits System.Web.UI.Page

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

IfNot IsPostBackThen

Me.DropDownList1.Items.Clear()

Dim objListItemAs ListItem

objListItem =New ListItem

objListItem.Text = 1

Me.DropDownList1.Items.Add(objListItem)objListItem =New ListItem

objListItem.Text = 2

Me.DropDownList1.Items.Add(objListItem)

objListItem =New ListItem

objListItem.Text = 3

Me.DropDownList1.Items.Add(objListItem)

EndIf

EndSub

PrivateSub DropDownList1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList1.SelectedIndexChanged

Me.DropDownList2.Items.Clear()

Dim objListItemAs ListItemobjListItem =New ListItem

objListItem.Text = 9

Me.DropDownList2.Items.Add(objListItem)

objListItem =New ListItem

objListItem.Text = 8

Me.DropDownList2.Items.Add(objListItem)objListItem =New ListItem

objListItem.Text = 7

Me.DropDownList2.Items.Add(objListItem)

EndSub

PrivateSub DropDownList2_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles DropDownList2.SelectedIndexChanged

Me.Label1.Text =Me.DropDownList1.SelectedValue +Me.DropDownList2.SelectedValue

EndSub

EndClass

Does this happen in both FF and IE6/7?


Definitely in IE6, as that's my default right now. I tried Firefox, and it does not seem to have this issue.

I also noticed that in IE6, when I select the item in the first list, the item is highlighted (dark blue background) until I move focus. When I select an item in the second list, the highlighting is removed. This could simply be because the focus shifted to the label. Neither list stays highlighted in Firefox.

So, it appears that it may be an IE quirk. Has anyone else seen this issue or found a work around? I should be getting IE7 on my PC in the next week or two, so maybe that will solve it!


IE6 blows. I know - Shocking news!

Try it out on IE7 and see if that fixes your problem.

I realize that some of the world is still using IE6, some can't even upgrade to 7 (ie. Win2K users) but I hate coding for that browser.


You should set the property of the UpdatePanel named "UpdatePanel2":updatemode="all"

question about modalpopupextender inside a gridview not working well?

hey all
can someone answer me why one works and the other doesnt?

this one works
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:LinkButton ID="lb1" runat="server" Text="+Add"></asp:LinkButton>
<asp:Panel runat="server" ID="addPanel" style="display:none">
add this: <asp:TextBox runat="server" ID="toAdd" Text="orig text"></asp:TextBox><br />
<asp:Button ID="addButt" runat="server" OnClick="addNote" Text="addButt" />
</asp:Panel>
</p
<AjaxToolkit:ModalPopupExtender ID="mpe1" runat="server"
TargetControlID="lb1"
PopupControlID="addPanel"
>
</AjaxToolkit:ModalPopupExtender>
</contenttemplate>
</asp:UpdatePanel
but this one does not work
<asp:GridView ID="gv" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:LinkButton ID="lb2" runat="server" Text="+Add2"></asp:LinkButton>
<asp:Panel runat="server" ID="addPanel2" style="display:none">
add this: <asp:TextBox runat="server" ID="toAdd2" Text="orig text2"></asp:TextBox><br />
<asp:Button ID="addButt2" runat="server" OnClick="addNote" Text="addButt2" />
</asp:Panel>
</p
<AjaxToolkit:ModalPopupExtender ID="mpe2" runat="server"
TargetControlID="lb2"
PopupControlID="addPanel2"
>
</AjaxToolkit:ModalPopupExtender>

</ItemTemplate></asp:TemplateField>
</Columns></asp:GridView
and this does not work either
<asp:UpdatePanel runat="server" ID="up2">
<ContentTemplate>
<asp:GridView ID="gv2" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>

<asp:LinkButton ID="lb2" runat="server" Text="+Add2"></asp:LinkButton>
<asp:Panel runat="server" ID="addPanel2" style="display:none">
add this: <asp:TextBox runat="server" ID="toAdd2" Text="orig text2"></asp:TextBox><br />
<asp:Button ID="addButt2" runat="server" OnClick="addButt_Click" Text="addButt2" />
</asp:Panel>
</p
<AjaxToolkit:ModalPopupExtender ID="mpe2" runat="server"
TargetControlID="lb2"
PopupControlID="addPanel2"
BackgroundCssClass="modalBackground"
DropShadow="true"
>
</AjaxToolkit:ModalPopupExtender>

</ItemTemplate></asp:TemplateField>
</Columns></asp:GridView>
</ContentTemplate>
</asp:updatepanel>

what happens in the the ones that dont work (ie, with the gridview)
is that the debugger throws an error that the addButt procedure cant find the textbox text

pls help!
i would love the third example to work

toy

welll did you give us the code for that procedure?

If textbox is in gridview you must use: ((TextBox)NameofGridView.FindControl("NameofTexBox")).Text - this is to call the text contained in the text box ...


thanks for the quick response

here is the code- behind

protected void addButt_Click(object sender, EventArgs e)
{
int uid = 1;

string newNote = "note";
newNote = toAdd.Text;

// suggested above but doesnt work
// newNote = ((TextBox)GridView2.FindControl("toAdd")).Text;

if (!string.IsNullOrEmpty(newNote))
{

// setup connx
SqlConnection conn = new SqlConnection(cs);
conn.Open();

string sql = "insertnote";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
SqlCommand cmd = new SqlCommand(sql);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@.note", newNote));
cmd.Connection = conn;

int numRowsAffected = cmd.ExecuteNonQuery();
conn.Close();

}
}

but correct me if im wrong - i dont think the code-behind really matters
because it works without the gridview
once i put the MPE in the gridview - thats when it breaks

also i tried your suggestion and that didnt work either
i think its cuase the textbox is in the MPE panel and not the gridview


Wednesday, March 21, 2012

Question about UpdatePanel

Hi !

I have a user control with an objectDataSource and a dropDownList. These controls are inside a user control because they will be reused in some pages.

This user control has a property that returns the selectedValue of the combo.

So, in one page I add the usercontrol, another objectdatasource and a gridview. The property in the first user control is a parameter for the 2nd objectDataSource.

So, I would like to eliminate the postback when I change the 1st combo. I tried to put the 2nd ObjectDataSource and the gridview inside an UpdatePanel and create a Triger linking with the user control property, but it fails, the gridview doesn't appears.

I tried some other combinations to, and nothing works.

So : how to use a web user control to trigger an UpdatePanel ?

The UpdatePanel identifies some properties of the controls, just some. Why ? What can I do to get my property in user control recognized by UpdatePanel triggers ?

Thanks!

P.S. : Sorry by my English, I don't speak English well.

[]'s

Dennes

Hi Dennes,

Although Visual Studio doesn't show custom properties on UserControls (it's a technical limitation in VS2005), you should be able to type it in manually in source view. At runtime it should all just work.

Thanks,

Eilon


Hi !

I already tried this, but doesn't work. I think It's because I'm using a web user control, trying to make a trigger point to a custom property in web user control. I think I need to do something more, but don't know exactly what.

Just pointing the trigger to the property doesn't work.

[]'s

Dennes


Hi Dennes, can you show me a sample that reproduces this problem?

Thanks,

Eilon


Hi, Eilon !

Here, the user control :

PartialClass usrComboInherits System.Web.UI.UserControlPublic ReadOnly Property Categoria()As Integer Get If ddlCategorias.SelectedValue <>""Then Return (ddlCategorias.SelectedValue)Else Return (Nothing)End If End Get End PropertyEnd Class

<%@. Control Language="VB" AutoEventWireup="false" CodeFile="usrCombo.ascx.vb" Inherits="usrCombo" %><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString%>" SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"></asp:SqlDataSource><asp:DropDownList ID="ddlCategorias" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID"></asp:DropDownList>

The page, default.aspx :

<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><%@. Register src="http://pics.10026.com/?src=usrCombo.ascx" TagName="usrCombo" TagPrefix="uc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" /> <uc1:usrCombo ID="UsrCombo1" runat="server" /> <br /> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString%>" SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [UnitsInStock] FROM [Products] WHERE ([CategoryID] = @.CategoryID)"> <SelectParameters> <asp:ControlParameter ControlID="UsrCombo1" Name="CategoryID" PropertyName="Categoria" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="None"> <FooterStyle BackColor="Tan" /> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" /> </Columns> <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /> <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" /> <HeaderStyle BackColor="Tan" Font-Bold="True" /> <AlternatingRowStyle BackColor="PaleGoldenrod" /> </asp:GridView> </ContentTemplate> <Triggers> <atlas:ControlValueTrigger ControlID="UsrCombo1" PropertyName="Categoria" /> </Triggers> </atlas:UpdatePanel> <br />   </form></body></html>

In this case, the postback still happens, the trigger is ignored. This same sample with a dropdownlist instead the user control works fine, the user control is the problem

So, I tried again, with the combo inside the UpdatePanel and no triggers. I get surprised, because it worked, but in my website It doesn't.

So, I couldn't reproduce the complete problem, just one part. My webpage is more complicated, it uses objectDataSource, call webservices and uses a customParameter (ReflectionParameter), uses a masterPage with other user controls in other parts of the complete page. One of these caused the problem with atlas, I'm still trying to discover.

My last try resulted in the following message :

Error : 'Sys.Application.findObject(...)' is null or not an object

[]'s

Dennes

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 re: Repeater control inside an UpdatePanel control.

I have a repeater control within an UpdatePanel and for the most part it is working as expected; however everytime thetimer control fires (to cause an asynch update) the rest of my web pageis not accessible until the callback has completed.

Icannot explain why this is happening. My dropdownlists are outside the UpdatePanel and my html links are inside the UpdatePane, yet they areall completely inaccessible for about 2 or 3 seconds while the callbackoccurs.

Has anyone seen this ? Shouldn't I be able to access my web page's control while a callback occurs ?

I can post code if someone can help.

Thank you,

Bob

It sounds like that entire page is posting back...

I would check to make sure that your UpdatePanel is set for Conditional update (although it probably is since you have a trigger connected to it).

I would put a label or something outside the updatepanel and fill it with current datetime to check if the entire page is posting back!


I just set it to Conditional but it's still doing the samething. Here's an outline of my code. This aspx page is connected to amaster page:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<asp:Timer ID="TimerOrders" runat="server" Interval="15000" />

<asp:UpdatePanel ID="UpdatePanelOrders" UpdateMode="Conditional" runat="server" >
<ContentTemplate>

<asp:Repeater ID="Repeater1"runat="server" OnDataBinding="Repeater1_DataBinding"OnItemDataBound="Repeater1_ItemDataBound"OnPreRender="Repeater1_PreRender" >
<HeaderTemplate>
...

</HeaderTemplate>

<ItemTemplate>
...

</ItemTemplate>
</asp:Repeater>


</ContentTemplate>

<Triggers>
<asp:AsyncPostBackTriggerControlID="DrpStatusList" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTriggerControlID="drpFilterList" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="TimerOrders" EventName="" />
</Triggers
</asp:UpdatePanel>


It looks fine. And I tried a similar deal and my outer controls work fine.

The only thing I can think of is that there is something with the server this is running on. It is getting hung up for some reason.

I will investigate further.


I'm running it from my local drive first, then I move the codeup to the Win2003 server. It works the same strange way on both sides.

Maybe it's masterpage related. Do you want to post your sample ?

Thanks,

Bob


Hi,Bob

Here is the sample:Using the UpdatePanel Control with Master Pages

It is hard to say where the problem lie on,Please double-check your code and find out what's the differences between your code and the sample's.

Thanks

Question: Report Viewer Control (SSRS) inside an Update Panel Control

Hi All,

My web application displays a report on one of its .aspx webpages coded in C#.

I am currently using a ReportViewer control to diplay the server report. I was trying to avoid the refresh of my report on every postback, by including it inside an AJAX Update Panel, it didn't work.

In my next trial, I tried to create a new report viewer control instance programatically and set its properties accordingly and then add this control to the Update panel'sContentTemplateContainer.Controls collection.

It looks like the control gets added to the Update Panel, however, It won't display on the page when it gets renedered. Below is a code snippet.

Please suggest. Thanks.

this.ReportViewer =newReportViewer();

this.ReportViewer.ID ="rvID";

this.ReportViewer.ServerReport.ReportServerUrl =newUri("http://ReportServer");

ReportParameter[] parm =newReportParameter[6];

parm[0] =newReportParameter("a","5");

parm[1] =newReportParameter("b","160");

parm[2] =newReportParameter("c","NYP-BOS");

parm[3] =newReportParameter("d","Coach");

parm[4] =newReportParameter("e","2007-01-01");

parm[5] =newReportParameter("f","2007-05-25");

PanelReport.ContentTemplateContainer.Controls.Add(this.ReportViewer); (adding the Report Viewer to the Panel)

this.ReportViewer.ShowParameterPrompts =false;

this.ReportViewer.ServerReport.SetParameters(parm);

this.ReportViewer.ServerReport.ReportPath ="/Reports/Report1";

Hi!

You should set theAsyncRendering="true"property of the ReportViewer (or setReportViewer.AsyncRendering =True in code-behind) to get async postbacks.

In that way, the report runs in an IFRAME which only refreshes when you re-render the report.

Let me know if it works for you or if you need the reports running in sync with the page. Some time ago I managed to use an UpdatePanel around them, but I ran into some issues that made me come back to the asyncrendering solution.


Hi, Thanks for the response, I have tried using that. It didn't work.

What I have is a Dropdown control, with Autopostback set to true; and an UpdatePanel somewhere else on the page. (the contenttemplate and triggers are empty on the .aspx page)

Programatically, inside the SelectIndexChange evenhandler for the dropdown, I am creating a ReportViewer control and set its properties as needed (also AsynRendering = true).

Now, I add this ReportViewer control to the control collection of the ContentTemplateContainer of the UpdatePanel.

I might be wrong in the sequence of the steps that I am doing...or something else, but whats happening is on the page I can see the report viewer template showing up which has 0 pages.

How and when does the report viewer control or the report gets rendered in the life cycle?

Thanks.


Hi!,

Yes, that may be the problem. The thing is that the SelectedIndexChanged gets fired even after the Page_Load, I'm not exactly sure "when" you have to generate the report, but could be too late. And a ReportViewer in asyncRender won't work inside an UpdatePanel, remeber that is actually an IFRAME.

But, if you are trying to fire an async postback for the SelectedIndexChanged event, the drop down list is the one that should be inside an UpdatePanel (you may already have that).
If that's you case, what you could do is add the ReportViewer outside the update panel and assign its properties in the markup code, and then call theReportViewer.ServerReport.Refresh() method on the SelectedIndexChanged event. If the ReportViewer is set to AsyncRender=true, you should have the same behavior as if it was inside an UpdatePanel.

Hope that helps,


Hi Juan, Based on your response I had partial success.

I made the following changes (Please note that my dropdown list is the first in a set of 3 cascading dropdown lists and all these are not inside any Update panel. They are working as expected whenever the selection changes on the first dropdown.

Took out the ReportViewer control from inside the Update panel and set the properties declaratively (AsyncRendering="true",ProcessingMode="remote",ShowParameterPrompts="false"and also added a <ServerReport> element with correct url and report path


Hi!, Well, I'm glad you are making some progress! :)

Mmmm...I'll start form your second question, and the answer is yes: You have to send the parameters set every time the report is generated.
Another option would be to use the embedded Report Parameters prompts, but it seems that you don't want to do that....
Remember that you can use ServerReport.GetParameters to get all you parameter info.

About the first one, what do you mean exactly when you say "the Report is not refreshing"?? Is trying to refresh, showing the "Generating Report" animated gif and then comes up blank?? It doesn't do anything at all? It comes up with an error??


Hey, that was quick! :)

Yes, I don't want the embedded parameter prompts.

Correct me if I am wrong, ServerReport.GetParameters gives me a readonly collection of parameter info objects right? what could I do with it?

Coming to the first question, By "not refreshing" what I meant was that the webpage sits with the report that it showed me on initial load, even on subsequent SelectIndexChange events (using debugger I can see the event being fired and the parameters being set and the call to report refresh). Its shows me the same report as If nothing happened, (the screen doesn't even flicker) I see the animated gif only on the initial page load.

I think..I would pick "doesn't do anything at all" from the choices that you have listed :)).

Thanks.


Hi!

Well, with the GetParameters you can get the Parameters Name, DataType, DefaultValue, etc,etc.
It's more useful if you want to dynamically create a toolbar or if you want to check that you are entering (SetParameters) all the required parameters with the right names, etc. You can build an array of Parameters and the use it's properties as reference in the SetParameters function.

About the report not refreshing, I would say that it's too late in the page life cycle to do that (as you can see, the SelectedIndexChanged event fires after Page_Load)
Having had a look at my solution, I saw that I'm refreshing the report on Page_Load avoiding to check for Page.IsPostBack.
Just to check, could you try NOT to refresh the report on SelectedIndexChanged and have a Button or something that refreshes the Report AFTER all the appropiate selections have been made in the DropDownLists? Just remember to move the code that sets the parameters and refreshes the reports to Page_Load.

Give it a try, if it works, you'll have the reason for your problem, altought maybe not the solution! :)

Cheers,


Based on the suggestion, I removed the code from the selectindexchange handler and placed something like the below in my page_load to test if the timinig in the lifecycle for the report refresh is the problem. I passed hard coded values to the parameters just so to make sure that the report output generated is different. The initial load was still good but not the postback, nothing happened on postback even from within the page_load. Sorry for all the trouble...I am desperately trying to get this working so as to complete an important assignment by this friday. Thanks.

page_load(object, EventArgs)

{

if (!IsPostback) /* Initial load*/

GenerateReport("a", "b", "c"); (some dummy values for this post)

else

GenerateReport("e", "f", "g"); // on postback

}

void GenerateReport( x,y,z)

{

reportparmeter [] parm = new reportparamete[3];

parm[0] = ..., parm [1] = ...; parm [2] = ...;

reportvwr.ServerReport.Setparameters(parm);

reprtvwr.ServerReprot.Refresh();

}


Mmmm..weird.......how are you generating the second post-back? Are you using a regular post back control like a Button outside an UpdatePanel?


I set the Autopostback on the first dropdownlist to true declaratively. I have a menu on my page too, so I can click on one of the menu items to generate a postback. In this case, should it matter how the postback is fired, because the page_load has hard coded calls for the report generation.

By the by, should the Asynrendering be set to true? (I have it set to true). I can't think of anything else..for now...ok time to go to work.

-Thanks


Hi Juan,

I noticed something, my report refreshes on only normal postbacks and not the asyncpostbacks. Is it okay to assume that, postbacks coming from any controls that are in some way related to an update panel (in or out of it) are always asyncpostbacks?

Thanks.


Hi!

Well, yes, that was the reason of my previous question: The reports will refresh only on a regular postback. If the control that fires the post back is not inside, but set as a trigger for some other update panel, it will fire an async postback.
If you put any control in a page, not inside and not associated with any UpdatePanel, a fire a postback from there, the reports work?

Cheers,


I have a hovermenu extender on my page not part of a update panel. The panel for the hover menu has a couple of link buttons. When I click those link buttons, a normal postback happens and my report gets refreshed.

This is so confusing, I am hoping that there is a thumb rule(s) of some kind for keeping things clear and simple with AJAX (or do's and don'ts). I am new to AJAX and I was wondering if you could recommend me a good design guide which says, how a particular functionality can be accomplished. Right now, I am just developing the code as I discover things, I am afraid if I end up making the code so inflexible for future changes.

Thanks.


What you are experiencing is exactly the same as I was:
The Reports could not be generated as a part of an async postback and in order to make them work properly they should be refreshed not later than in Page_Load...These could be two rules of thumb.

Keep in mind that the ReportViewer runs in a IFRAME while in asyncRendering=true, so it may be worthwhile investigating the interactions between these and AJAX...

Question: UpdatePanel and TwoWay binding

I have a FormView control and UpdatePanel inside EditItemTemplate. It seams like ControlBuilder doesn't generate ExtractValues for controls that are in UpdatePanel and in result their values doesn't get updated.

I wonder if this behavior is by design or it is bug?

Thanks!

do u try this in the page_load event?


See the example

<asp:FormViewID="FormView1"runat="server"DefaultMode="Edit" DatasourceID="ObjectDS"><EditItemTemplate>

....

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="conditional"><ContentTemplate><asp:DropDownListID="lstType"SelectedValue='<%# Bind("TypeID")%>'runat="server"DataSourceID="TypeDS"DataValueField="ID"DataTextField="Name"AutoPostBack="true"></asp:DropDownList><asp:TextBoxID="txtTypeDescription"runat="server"Text='<%#Bind("TypeDescription") %>'Enabled='<%#Eval("TypeID").ToString()=="Other"%>'/></ContentTemplate></asp:UpdatePanel>

...

</EditItemTemplate></asp:FormView>

When I call Form1.UpdateItem() values for "TypeID" and "TypeDescription" fields are not updated in the DataSource. I have found that in "__ExtractValues" method generated by ASP.NET the code for extracting values from "txtTypeDescription" and "lstType" is missing so their values are not passed to the DataSource. If I remove the UpdatePanel evrithig is OK and the code appears again. I have found that that EditItemTemplate property of the FormView control is marked with [TemplateContainerAttribute(typeof(FormView), BindingDirection.TwoWay)] and ContentTemplate of a UpdatePanel is not. So I wonder if this behavior is by design or it is a bug?

Workaround is to place the whole FormView in the UpdatePanel.


you have some issue as link below:

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

you have to add build your dropdownlist first then add UpdatePanel later.

so you can do it in the page_Load and add UpdatePanel in code behind.

Hope this help