Showing posts with label usercontrol. Show all posts
Showing posts with label usercontrol. Show all posts

Wednesday, March 28, 2012

PageMethods in UserControl

Sorry if this has been asked before, but the search on the forum does not appear to be working. Everything returns "no results" even a search on "atlas"Smile [:)].

Anyway, is it possible to have web methods in a usercontrol and call them from javacript. I have successfully implemented the PageMethods.SomeMethod from a page but not from a User Control.

Anyone know how to do this?

Thanks,

Joe

No, PageMethods on user controls are not supported.


Will PageMethods be supported the future. I was planning on using PageMethods in controls, to me this would make sense to have.

Thanks.

hello.

i'm tented to say that it won't happen...though i might be wrong...


If there is some callback functionality that you need to use on different pages throughout your site, the best way forward would be to use the asmx web service model. This is much easier than it sounds, and the tutorial is great.

This model is more efficient than PageMethods, where ASP.NET has to initialise a Page instance from viewstate/http to get access to the method you need.

It seems to me that UpdatePanel and PageMethods have been included primarily because of ease of integration into existing sites. If you have the time to optimise, however, then the web service model is the way to go...

Cheers,
Carlos
Hi, thanks for the informaiton. can you send me an example how to use webservice model with user controls..

Monday, March 26, 2012

PageMethods is undefined when calling webservice from usercontrol

I have the following code to call a webservice in an aspx file. But the same code does not work in a usercontrol that I have created. I always get the message that 'PageMethods is undefined'. On the aspx page it generates the following:

<script type="text/javascript">
<!--
var PageMethods = { HelloWorld:function(s,onMethodComplete, onMethodTimeout, onMethodError) {return Web.Net.PageMethodRequest.callMethod("HelloWorld",{s:s}, onMethodComplete, onMethodTimeout, onMethodError); }
}
// -->
</script>

but in the usercontrol this variable is not generated. The following is the code in the aspx page which is very similar to the code in the user control. Please help!

<atlas:ScriptID="Script1"runat="server"Path="~/ScriptLibrary/AtlasCompat.js"Browser="Mozilla"/>

<atlas:ScriptID="Script2"runat="server"Path="~/ScriptLibrary/AtlasCompat.js"Browser="Firefox"/>

<atlas:ScriptID="Script3"runat="server"Path="~/ScriptLibrary/Atlas.js"/>

<scripttype="text/C#"runat="server">

[WebMethod]

publicstring HelloWorld(string s)

{

return"Hello '" + s +"'";

}

</script>

</head>

<body>

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

Enter your name:

<asp:TextBoxid="nameTextBox"runat="server"></asp:TextBox>

<buttonid="buttonGo"onclick="return OnbuttonGo_click()">GO</button>

</form>

<scripttype="text/javascript"language="JavaScript">

function OnbuttonGo_click()

{

//textbox string value passed as a param to the server method

PageMethods.HelloWorld(document.getElementById("nameTextBox").value, OnWebRequestComplete1);

returnfalse;

}

PageMethods are currently not supported inside user controls. I've open a bug to track that issue. Thanks.


If I put the WebMethod in the calling page I can call it from the usercontrol, which allows for the functionality that I desire. This is not as clean as I hoped for but it will work.

Thanks


Has this been fixed in the December release? It appears not, unless I am doing something incorrect. I am getting the js error 'Web' is undefined. Even my work around for this problem apears to be broken.

Wednesday, March 21, 2012

partial page update in a usercontrol on a master page

OK, I've installed AJAX Extensions, watched the tutorial video and tried to use the partial page update as follows: I have a user control which contains hyperlinks for paging back and forth and a datalist which displays the current page of products: <asp:UpdatePanelID="UpdatePanel1"runat="server"> <ContentTemplate> <asp:HyperLinkID="hLink_Previous"CssClass="paging_Text"Visible="false"runat="server">Previous</asp:HyperLink> <asp:LabelID="label_Paging"CssClass="paging_Text"Visible="false"runat="server"/> <asp:HyperLinkID="hLink_Next"CssClass="paging_Text"Visible="false"runat="server">Next</asp:HyperLink> <asp:DataListID="dataList_Products"RepeatColumns="2"RepeatDirection="Horizontal"runat="server"EnableViewState="False"OnItemCommand="dataList_Products_ItemCommand"> <ItemTemplate> <tableclass="dataList_Products_Table"cellpadding="0"align="left"> <trclass="dataList_Products_Table_Row"> <tdalign=centerclass="dataList_Products_Table_Cell_1"> <ahref='Product.aspx?P=<%# Eval("ProductID")%>'> <imgclass="small_Image"src='ProductImages/<%# Eval("Image1FileName")%>'/> </a> </td> <tdclass="dataList_Products_Table_Cell_2"> <aclass="product_Name"href='Product.aspx?P=<%# Eval("ProductID")%>'> <%# Eval("Name")%> </a> <br/> <spanclass="product_Description"> <%# Eval("Description")%> <br/> <br/> Price: </span> <spanclass="product_Price"> <%# Eval("Price","{0:C}")%> </span> <br/> <asp:ButtonID="btn_AddToCart"Text="Add to Cart"CssClass="small_Button_Text"CommandArgument='<%# Eval("ProductID")%>'runat="server"/> </td> </tr> </table> </ItemTemplate> </asp:DataList> </ContentTemplate></asp:UpdatePanel> I use this within the contentPlaceHolder on the Master page. I want only this bit to update when I navigate between pages but looking at the triggers collection, I can only see the datalist and ScriptManager controls - how do I hook into the previous and next page hyperlinks and their onClick event to enable the page update ? Thanks AR

Hi,

HyperLink control doesn't have click event.

You can use LinkButton control that has a similar layout like hyperlink to achieve so.

Hope this helps.