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

Wednesday, March 28, 2012

change the visable of page controls

in my UserControl,there are 3 controls, DropDownList1,DropDownList2,TextBox1

DropDownList1,DropDownList2 are for the ajaxToolkit:CascadingDropDown

TextBox1.Visible=false;

but now when DropDownList1.SelectedItem.Text=="other",I want to change DropDownList2.Visible=false;TextBox1.Visible=true;

I make it via AJAX

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="TypeService.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
</Scripts>
</asp:ScriptManager>

<script language="javascript">

...

Type_service.CheckOther(DropDownList1.value);

....

</script>

but the problem is now

how my TypeService.cs call the function in the CascadingDropDown.ascx.cs

Hi,shootarrow

I'm afraid that you cann't do this in that way.

You can do this at the client side!

Try this:

Default.aspx:

<%@. Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
// This function calls the Web Service method.
function EchoUserInput()
{
//Do something you want to do, e.g.delay the script execution
var echoElem = document.getElementById("EnteredValue");
WebService.HelloWorld(echoElem.value,SucceededCallback);
}
// This is the callback function that processes the Web Service return value.
function SucceededCallback(result)
{
var RsltElem = document.getElementById("Results");
RsltElem.innerHTML = result;
// Change the delay of the script execution back.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<h2>
Simple Web Service</h2>
<p>
Calling a simple service that echoes the user's input and returns the current server
time.</p>
<input id="EnteredValue" type="text" />
<input id="EchoButton" type="button" value="Echo" onclick="EchoUserInput()" />
</div>
</form>
<hr />
<div>
<span id="Results"></span>
</div>
</body>
</html>

WebService.asmx:

<%@. WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(String input)
{
System.Threading.Thread.Sleep(3000);
string inputString = Server.HtmlEncode(input);
if (!String.IsNullOrEmpty(inputString))
{
return String.Format("You entered {0}. The current time is {1}.", inputString, DateTime.Now);
}
else
{
return "The input string was null or empty.";
}
}
}

Hope this helps.

Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115018.aspx

Change full postback action from inner update panel...

Hi,

Is there a way to alter full postback to partial postback caused by outer update panels from usercontrol?Huh?Confused...I tried to add button control as an AsyncPostBackTrigger. No effect to change from a full page postback to partial one. No change whether I set properties like ChildrenAsTriggers to false/true and UpdateMode to Always/Conditional inner update panel, when a button or any control causes a postback action is pressed, it causes a full postback.


Parent:

<asp:UpdatePanel ID="upanelPage" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<asp:UpdatePanel ID="upanelMainContent" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<!-- Main Content --> <<-- my user control or other are displayed
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>

User Control loaded to Parent...

<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false" >
<ContentTemplate>
<ajaxToolkit:TabContainer ...>
<ajaxToolkit:TabPanel ...>
<asp:MultiView...>
<asp:View...>
...
<asp:LinkButton...></asp:LinkButton>
<asp:Button...></asp:Button>
<asp:UpdatePanel ...>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=.../>
</Triggers>
<ContentTemplate>
...
<asp:GridView...>
</asp:GridView>
...
</ContentTemplate>
</asp:UpdatePanel>
...
</asp:View...>
<asp:View...>
...controls...
</asp:View>
</asp:MultiView>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ...>

</ajaxToolkit:TabPanel>
...
</ajaxToolkit:TabContainer>
</ContentTemplate>
</asp:UpdatePanel>

UpdatePanel causes a Full Post Back no matter what properties you set on it.

If you are looking for better performing alternatives, look out for ScriptCallbacks or JSON Based Calls and this would require "some" work compared to ourmagic updatepanel!


Huh??ConfusedScriptCallbacks?ConfusedJSon Based Calls?Hmm...Does not know what are they or how to start with them? ..thanks for the reply..


Huh??ConfusedScriptCallbacks?ConfusedJSon Based Calls?Hmm...Does not know what are they or how to start with them? I was trying to control the postback action of outer update panel from the inside user control..thanks for the reply..


Hi,den2005

I found that the following code worked.

The Page:

<%@. Page Language="C#" %>

<%@. Register src="http://pics.10026.com/?src=WebUserControl2.ascx" TagName="WebUserControl2" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanel Tutorial</title>
<style type="text/css">
#UpdatePanel2 {
position: relative;
margin: 2% 5% 2% 5%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ChildrenAsTriggers="False" ID="UpdatePanel1" UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<fieldset>
<legend>Parent UpdatePanel</legend>Last refresh
<%=DateTime.Now.ToString() %>
<br />
<asp:Button ID="Button1" runat="server" Text="Refresh Outer Panel" />
<uc1:WebUserControl2 ID="WebUserControl2_1" runat="server" />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

The UserControl:

<%@. Control Language="C#" ClassName="WebUserControl2" %>
<asp:UpdatePanel ChildrenAsTriggers="False" ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<legend>Nested UpdatePanel</legend>Last refresh
<%=DateTime.Now.ToString() %>
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Calendar1" />
</Triggers>
</asp:UpdatePanel>

Hope this help.

Best regards.

Jin-Yu Yin

Change dropdown selectedvalue in usercontrol, in a page.aspx

Hello,

i have a usercontrol (reservas.ascx) with one dropdown list (dropHoteis) inserted in one masterPage.
In my default.aspx, that is a content page of that masterPage...
How can i change the selected value in the dropdown list (dropHoteis) from my default.aspx?

1. In reservas.ascx, i put the Class Public...
2. In Default.aspx.vb, how can i reference the reservas.ascx?? I tryed, but not appear in my @dotnet.itags.org.Imports... why?

Thanks for your help!

From the page you can useMe.Master.FindControl("IdOfUserControl") which will get you the reference to your user control.

-Damien


Hep, ok...

But in my UserControl how can i declare the "function/property" to change the selectedValue of the dropdownlist??

Example:

Public Property DropSelectedValue(ByVal hotelAs String)Set(ByVal value) dropHoteis.SelectedValue = valueEnd Set Get dropHoteis.SelectedValue = hotelReturn dropHoteis.SelectedIndexEnd Get End Property

This not work for me!! :(

throw: Object reference not set to an instance of an object!!


in the usercontrol's code behind write a public property in which you have to set the dropdown list's value. u can then access that property from your page.aspx using the usercontrol name and can set the value of the dropdown list.

Regards & have a nice day ahead

Monday, March 26, 2012

catching the postBacks of UserControl inside another UserControl

My problem is that i've got:

MasterPage with a Menu, ScriptManager and a UpdatePanel, inside of wich i've put the the ContentPlaceHolder. I've put the Menu as trigger for the UpdatePanel

In the ContentPage i want to show, i have a UserControl that has inside of itself another UserControl.

Even putting an UpdatePanel in the ContentPage containing the UserControl (Parent), the whole page refreshes instead of been only the ContentPage, due to the UpdatePanel of the MasterPage.

All the UpdatePanels have de UpdateMode as Conditional.

How can i make this work, refreshing only the contentPage or the area pretended of the contentPage?

i've seen other Posts, but they only talk of one UserControl.

Thanks a lot.

You've got two problems:

First, the menu control is not compatible with partial-page updates and therefore not compatible with updatepanel controls.

Second, if you are using a master page, you are going to get a full refreshevery time you load a content page. When you navigate to a content page, you are not just reloading the part of the page that is in the contentplaceholder. You are loading anentire page that is a meshing of the master and content page. So what you are trying to do is not possible. Placing an updatepanel around a contentplaceholder does nothing. Different page = refresh.


thanks for your answer, but what i meant was the case of the usercontrols. the use of them makes me refresh the whole page, even though the content page is inside a update panel, i've tried to put the control inside a updatepanel conditional mode, but it still doesn't work.

this usercontrol was another one inside itself.


See if this article helps:

http://asp.net/ajax/documentation/live/tutorials/UsingUpdatePanelUserControls.aspx