|
Do you set a value for the ID of the dynamic user control? If you don't, you'll need to do because in the first time you load and add the dynamic control in the event handler of the radio buttons, and the control is readded on postback in another event which should occurs early in the control life cycle in order for the postback event (SelectedIndexChanged) work. So if you don't specify an id for the control, the ASP.NET will automatically generate the id for the control. And as a result of that, the control has different id values, and the ASP.NET cannot process the posted data. From the second time on, the control is always added in an event until you select a new action from the radio buttons, so the auto-generated id of the user control is the same, the ASP.NET can process the postback data and the SelectedIndexChanged event gets fired. Below is a simple example to demonstrate what you might want to do, the sample code consists of the web user control and the testing web page.
--------Web User Control sample code -----------
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="SampleWeb1.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server" Visible="true"></asp:TextBox>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" Visible="false" AutoPostBack="True" On_SelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Text="Item1" Value="Item1" Selected="True"></asp:ListItem>
<asp:ListItem Text="Item2" Value="Item2" ></asp:ListItem>
<asp:ListItem Text="Item3" Value="Item3" ></asp:ListItem>
<asp:ListItem Text="Item4" Value="Item4" ></asp:ListItem>
</asp:DropDownList>
namespace SampleWeb1
{
public partial class WebUserControl1 : UserControl
{
public string Action
{
get
{
if (ViewState["Action"] == null)
ViewState["Action"] = "Create";
return (string)ViewState["Action"];
}
set
{
ViewState["Action"] = value;
SetControlVisibility();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
SetControlVisibility();
}
private void SetControlVisibility()
{
TextBox1.Visible = (Action == "Create");
DropDownList1.Visible = !TextBox1.Visible;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write(string.Format("New selected value: {0}<br/>", DropDownList1.SelectedValue));
}
}
}
--------Testing web page -------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SampleWeb1._Default" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<asp:RadioButtonList runat="server" ID="rdoActionList" AutoPostBack="True" On_SelectedIndexChanged="rdoActionList_SelectedIndexChanged">
<asp:ListItem Text="Create" Value="Create"></asp:ListItem>
<asp:ListItem Text="Edit" Value="Edit"></asp:ListItem>
<asp:ListItem Text="Delete" Value="Delete"></asp:ListItem>
</asp:RadioButtonList>
<asp:PlaceHolder runat="server" ID="PlaceHolder1">
</asp:PlaceHolder>
</form>
</body>
</html>
namespace SampleWeb1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string CurrentControlUrl
{
get
{
if (ViewState["CurrentControlUrl"] == null)
return string.Empty;
return (string)ViewState["CurrentControlUrl"];
}
set
{
ViewState["CurrentControlUrl"] = value;
}
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if (!string.IsNullOrEmpty(CurrentControlUrl))
{
WebUserControl1 control = (WebUserControl1)LoadControl(CurrentControlUrl);
control.ID = "WebUserControl1";
PlaceHolder1.Controls.Add(control);
}
}
protected void rdoActionList_SelectedIndexChanged(object sender, EventArgs e)
{
//Persist the dynamic user control to reload it on postback.
CurrentControlUrl = "WebUserControl1.ascx";
WebUserControl1 control = (WebUserControl1)LoadControl(CurrentControlUrl);
//Explicitly specify the id of the control.
control.ID = "WebUserControl1";
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(control);
control.Action = rdoActionList.SelectedValue;
}
}
} Last modified: Thursday, July 27, 2006 12:16:05 AM --
|
|
|
|
|
Halleluja!
The ID did the trick - just had to add it to the user ctrl whenever I loaded it.
Thank you very very very much for the help
|
|
|
|
|
hi
i'm facing a weird situation..i hav uploaded all my project on the client server.
but RequirdField Validator,Compare Validator and RegularExperssion is not working on server..but they are working fine on local host.
how is it possible and what to do slove it.
on server no validator control is working
thanx
|
|
|
|
|
Try this....
upload a copy of WebUIValidation.js to a directory
within your application.
Add the following line to your web.config
<webControls clientScriptsLocation="YourApp/YourScriptsDirectory/" />
hope this work
Nav.
|
|
|
|
|
I am using .NET 2.0 C#. How do I sort the data in a gridiew.
I constructed the data manually. Is there any sample or link?
thanks in advance. Much appreciated.
|
|
|
|
|
You need to sort it before binding to the grid. How to sort it depends on what structure it is in.
|
|
|
|
|
|
Good Day !
Did anyone know how to pass a whole data from one .aspx page to another .aspx page? Can anyone give me a sample code or solution. Thanks..
Best Regards,
Pei Sun
|
|
|
|
|
You can paas the data from one page to another page in multiple way. One simple way is to pass it through querystring. Here your data will be there with the URL and in the next page you can retrive the data from the querystring.
Best Regards,
Apurva Kaushal
|
|
|
|
|
can you give me sample code as a reference?
Best Regards,
Pei Sun
|
|
|
|
|
What you need to do is when you are redirecting to another page the you have to pass the value with the URL like this:
Response.Redirect("page2.aspx?ID=1234");
And in page2 you can access the value of ID like this:
string str = Request.QueryStering["ID"].ToString();
Best Regards,
Apurva Kaushal
|
|
|
|
|
Response.Redirect("page2.aspx?ID=1234");
What is the meaning of the ID=1234? The ID is declare by us? The coding is just simple like this? Do you have any reference site talk about this problem? Thanks..
Best Regards,
Pei Sun
|
|
|
|
|
here id is a variable in which you are storing the value. whatever value you will store in that you can access it in the next page. And also if you are sending the value through querystring then it will be visible to the user so important data should not be sent through querystring. alternatively you can use session for this purpose.
Best Regards,
Apurva Kaushal
|
|
|
|
|
hi apurva
sorry yaar i may be disturbing u
but plz try to solve my problem.
i'm facing a weird situation..i hav uploaded all my project on the client server.
but RequirdField Validator,Compare Validator and RegularExperssion is not working on server..but they are working fine on local host.
how is it possible and what to do slove it.
on server no validator control is working
thanx
|
|
|
|
|
What you check is javascript files on the server. particularly this file "WebUIValidation" this is required for the validation controls.
Best Regards,
Apurva Kaushal
|
|
|
|
|
hello apurva
thanx..for replying
i got u but problem with me is that i'm working for a US client then how could i do changes in his server or what i hav to do for it.
and what should i ask to client for this matter.
tell me.
thanx
|
|
|
|
|
i dont think that you can do any change on there server but you need to know about the folder and i not too sure about how you can check it on there server. Alternatively you can discuss this your senioy on how to handle this.
Best Regards,
Apurva Kaushal
|
|
|
|
|
There is alot of method to go about it. And it is even better if you are using the current .NET 2.0 with the postbackurl property.
thanks in advance. Much appreciated.
|
|
|
|
|
But i'm using .Net 1.1 is there any other solution or sample code you can show to me? Thanks..
Best Regards,
Pei Sun
|
|
|
|
|
To pass data in-between forms, u have several options. To get a proper overview, search for state management in MSDN.
For immediate help:
string name = "Pei Sun";
Arraylist nickNames = new Arraylist(3);
nickNames.Add("PeSun");
DataSet ds = new DataSet();
//1. You can use HttpCookie which represents a cookie stored on the client's machine.
HttpCookie myData = new HttpCookie("CookieName");
myData.Expires.AddMinutes(5);
myData.Values.Add("name", name);
myData.Values.Add("nickNames", nickNames);
//add ds in the same way.
//Then add the cookie to the HttpSession.Cookies collection
HttpSession.Cookies.Add(myData);
//And thats it. You can redirect to your new page.
Live in fragments no longer. Only connect.
|
|
|
|
|
Hi ,
How to get time in 24 hours format in ASP.NET 1.1
Regards,
Uma
|
|
|
|
|
Hi Uma
try this
DateTime dtNow = DateTime.Now;<br />
string str24Hrs = dtNow.ToString("T",System.Globalization.CultureInfo.InvariantCulture);
regards
GV Ramana
|
|
|
|
|
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
Make sure the HH is in upper case, that makes it military time (24 hrs format)
Nila Fridley
|
|
|
|
|
Hello Friends,
Can anyone tell me how to print a datagrid in a window application using C#. Iam having a very big grid. first it should be shown to a printpreview page and from there it has to be printed. Help me to get the entire grid to a printpreview page.
Vipin
|
|
|
|
|
Try the c# forum, this is for web based apps.
|
|
|
|