Showing posts with label manager. Show all posts
Showing posts with label manager. Show all posts

Wednesday, March 28, 2012

PostBack is happening even after using Update Panel and Script Manager

Hi,

I have a ASP.NET web application. I have a gridview and using a RowDataBound andRaisePostBackEventevent for getting the GridView details in the controls below like textboxes, dropdown etc. Now i am using Ajax Extensions controls like Update Panel and Script manager to avoid a postback happening when the GridView row is clicked. Even after implementing them postback is happening. Please see the code bits and let me know if i am missing somewhere.

UI

<asp

:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"></asp:ScriptManager>

<

asp:UpdatePanelid="UpdatePanel1"runat="server"UpdateMode="Conditional">

<contenttemplate>

<asp:GridViewID="GridView1"runat="server"OnRowDataBound="GridView1_RowDataBound"CssClass="sampletable"AlternatingRowStyle-CssClass="d1"ShowHeader="true"ShowFooter="false"AllowPaging="true"AllowSorting="true"AutoGenerateColumns="false"DataKeyNames="ProjectID"Width="100%"PageSize="5"><Columns>

<asp:BoundFieldVisible="false"HeaderText="Project ID"DataField="ProjectID"SortExpression="ProjectID"/><asp:BoundFieldHeaderText="Project Name"DataField="ProjectName"SortExpression="ProjectName"/><asp:BoundFieldHeaderText="Site Name"DataField="SiteName"SortExpression="SiteName"/></Columns></asp:GridView><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:ButtonID="Button1"runat="server"Text="Button"/>

</

contenttemplate>

<

Triggers>

<

asp:AsyncPostBackTriggerControlID="GridView1"EventName="RowDataBound"/>

</

Triggers>

</

asp:UpdatePanel>

And theCode behind for RowDatabound event is

protected

void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)

{

try

{

if (!((e.Row.RowType ==DataControlRowType.Pager) || (e.Row.RowType ==DataControlRowType.Header) || (e.Row.RowType ==DataControlRowType.Footer)))

{

System.Web.UI.

ClientScriptManager cs = Page.ClientScript;//Assign Row Index. This row index used in finding the ID of the clicked rowint intRowIndex = e.Row.RowIndex;

e.Row.Attributes.Add(

"onClick", cs.GetPostBackEventReference(this, intRowIndex.ToString().Trim()));

e.Row.Attributes.Add(

"onKeyDown","if( event.keyCode == 13 ) " + cs.GetPostBackEventReference(this,"KEYDOWN" +"$" + e.Row.DataItemIndex.ToString().Trim()));

}

}

catch (System.Exception ex)

{

//OnError(ex);

}

}

The code looks good, did you try a easy test to see if the postback is hidden?

http://alpascual.com/blog/al/archive/2006/12/21/Code-Snip-_2200_AJAX-Timer_2200_.aspx

Try the sample below and let me know if you see the postback


Thanks for the Quick Response.

But i could not get exactly what you want to convey.

regards,

Parimal


Ok, wrap a asp:button around an updatepanel and let me know if you see the postback

Hi,

The button is working fine without any post back. The Post back is happening when Grid Row is clicked as it call the RaisePostBack event to get the Row details. That event is coded as we have not used any command template in Grid.

regards,

Parimal


OnRowDatabound would not make sense for an async trigger. The user clicking the row and getting a postback via the javascript you added to the onclick is not the same. If you take out the trigger and just add ChildrenAsTriggers="true" to the UpdatePanel it would probably work as you expect.

One other thing - in this code:

"onClick", cs.GetPostBackEventReference(this, intRowIndex.ToString().Trim()));

e.Row.Attributes.Add(

"onKeyDown","if( event.keyCode == 13 ) " + cs.GetPostBackEventReference(this,"KEYDOWN" +"$" + e.Row.DataItemIndex.ToString().Trim()));

Change "this" to GridView1. You want to create a postback for your gridview, not the whole page. Since you're creating a custom postback you'll also need to register for event validation, or disable event validation in your page.


Thanks for the response. But still post back is happening. I will explain in details

1. I have a Gridview RowDataBound event which fires when Data is bounded to Grid.

2. I have aRaisePostBackEvent which fires when the row in the Grid is selected and this causes the Post Back event.

3. Aslo my UserControl is implementingIPostBackEventHandler interface.

Thanks in Advance,

Parimal

PRB: Master Pages and Update Panels/Script Manager - AJAX Magic not working

I have a master page that has the script manager control and a content place holder

I have a content page that is using the above master page and with a gridview control wrapped in an update panel

When the content page doesn't use master pages and the script manager is placed within the content page along with the panel, everything works fine

The problem arises when the master page has the script manager and thhe content page just has the update panel with the gid view. It seems to be doing a regular postback and the ajax plumbing doesn't seemto have any effect..

I also tried adding a page initi handler and specifying the trigger in the code behind but with no luck..

generated page source with script manager in master page is listed below. Why does gettting a common master page scnario be so difficult to getv it working..Please point me in the right direction

<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('_ctl0:ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['t_ctl0:ContentPlaceHolder1:panel1'], [], [], 90);

//]]>
</script>


Genertated source when the script managersits on the page and the content page does not use any master pages

<script <script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('aspnetForm'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tpanel1'], [], [], 90);

//]]>
</script>

Hi Ajaxnewbie,

Could you please post your code, so we can see how you have implemented it. Thanks

Regards,


Good question... I have exactly the same problem. I wish there would be a valid answer for this post.

thanks!

Monday, March 26, 2012

Probblem with Menu control inside an update panel

Hi,

I have a master page with a script manager ,update panel and Content Palce Holder. in the default page which uses the masterpage I have added a menu control, textbox and a button. I have two problems which I have seen in the past in other versions of ajax. I have not coded anything other than just these controls on a page

1) I could click on button all day long and there is no java script error but as soon as I click on a menu item I get javascript error saying:

Line:221

Char:20

Error '0.cells' is null or not an object

code: 0

2) I can not get my CSS sheet work in my app theme for the background images. I have the following code in my CSS

.Menu1BackGround

{

background-image:url(/Images/Menu1_Background.bmp);

}

and I have assigned the it to the menu. Nothing happens as if it does not recognize the image path. I could add the background:black to the code and it works fine for the color but not the image. I am not sure if thisis because of the same problem.

Any body have any ideas?

Thanks

Seehttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls. The Menu control is not supported inside an UpdatePanel.

I have been using this piece of javascript to go around the menu problem:

var oldMenu_HideItems = Menu_HideItems;if(oldMenu_HideItems){Menu_HideItems = function(items){if (!items || ((typeof(items.tagName) =="undefined") && (items instanceof Event))) { items = __rootMenuItem; }if(items && items.rows && items.rows.length == 0){ items.insertRow(0); }return oldMenu_HideItems(items);} }
I got it from the asp:menu javascript code and I hook it to "patch" the problem.
Adding it to a page where a menu resides makes the javascript error go away. 

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

HTH


Menu control is not compatable with AJAX.

I m also facing sme problem..