i have url like this : DossierSoin_Fiche.aspx?SoinId=1
how can i pass this SoinId into dx:ASPxPopupControl
<dx:ASPxPopupControl ID="ASPxPopupControl_Surveill"
ContentUrl="~/PopUp/Surveillance.aspx?SoinId=<%=SoinId %>" ?
thanks you in advance
PS : i can not use code behinde, because it will reload the page, then i will lost the data that have not save in database. I use callback instead, so i need pass this querystring value on aspx not in aspx.cs
In your containers codebehind:
protected string SoinId
{
get
{
return Request["SoinId"];
}
}
And use the code you have.
make a property "SoinID" (if you dont already have one)
protected string SoinId {get;set;}
(type of modifier is up to the OP, could also be public).
then, assign a value to the property in your page_load:
SoinId = Request.QueryString["SoinID"];
your .aspx code can stay the same if you use it like this.
Just pass the value to the public property in the CodeBehind of the page.
ASPxPopupControl_Surveill.ContentUrl = ...
[edit made with thanks to rs.]
Option A:
1) Declare a protected variable named SoinId in the scope of your aspx page.
2) In the Page_Load event, add this:
if(!Request.QueryString["SoinId"]==null)
{
SoinId = Request.QueryString["SoinId"];
}
Opetion B:
Replace your aspx code with this:
<dx:ASPxPopupControl ID="ASPxPopupControl_Surveill"
ContentUrl="~/PopUp/Surveillance.aspx?SoinId=<%=Request.QueryString["SoinId"] %>">
Edit: Consider using a property as other colleagues proposed. It's more ellegant.
I would imagine you could just assign the value in the code behind.
e.g.;
ASPxPopupControl_Surveill.ContentUrl = "~/PopUp/Surveillance.aspx?SoinId=" + Request["SoinId"].ToString();
Related
In the below code i have a hidden value in sample.ascx and i want to use that value in sample.aspx in its codebehind.pls help me to do this.
Sample.ascx
txthidd.Value = "Hai";
<asp:HiddenField ID="txthidd" runat="server" />
You can create a Public property in your ascx like this
public string txt
{
get
{
return this.txthidd.Value;
}
}
and can access this in aspx like this
string textOnAspx = UC_UserControl.txt;
In the codebehind, you should create a property getting the field:
public string TxtHidText{
get
{
return txthidd.Value;
}
}
Then, you'll reference it per the id, let's say you'll have something like this in ASPX:
<u1:Sample id="SomeSampleContentOfThePage" />
and in codebehind, it will be accessible via
var text = SomeSampleContentOfThePage.TxtHidText;
Note that if you want to set it from the other aspx, you should create a set part as well.
I have a web page and it contains an user control inside of it. I have a property on the aspx page which gets set in the pageinit method and I need to that propery on ascx page.
How can I get it?
Create a public property inside the ascx and set it at the same time you set in the aspx page.
Just to let you know, PreInit is a EventHandler not a method.
MyAdminPage myPageInstance = this.Parent as MyAdminPage;
if(myPageInstance != null)
{
...
}
There has been a few questions on this.
Reference .aspx property from .ascx
The easiest options are as follows:
Use a public variable and access it from the parent page.
Assign the variable to a hidden field on the ascx front end. A field like this: <asp:HiddenField ID="ascxField" runat="server" /> .
The example below is for #1, but #2 is almost the same.
Example #1:
Aspx page:
Front end:
<%# Register TagPrefix="Admin" TagName="MyUserControl" Src="~/UserControls/.../MyUserControl" %>
...
<Admin:MyUserControl ID="MyUserControl" AutoPostBack="true" runat="server" Visible ="false" />
Code Behind:
this.MyUserControl.Variable1 = 1;
this.MyUserControl.Variable2= "value";
Ascx page:
Code Behind
public int Variable1 { get; set; }
public string Variable2 { get; set; }
I have a master page which has a content section with the id cpMainContent.
I am using this master page on every webform I am creating for college project. One of such form is frmSearchPersonnel. The purpose of frmSearchPersonnel is to ask user last name of the person they want to search in a textbox and then click on search button. The ID of TextBox is
txtSearchName
Search button will do postbackUrl transfer to another form which I have named frmViewPersonnel.
In frmViewPersonnel I am trying to use following code.
NameValueCollection myRequest = Request.Form;
if(!string.IsEmptyOrNull(myRequest["txtSearchName"]))
string strSearch = myRequest["txtSearchName"];
The problem I ran into is that this didn't find any control with the name of txtSearchName. While debugging I found this in myRequest object,
[5] "ctl00$cpMainContent$txtSearchName" string
Even though when I added textbox I gave it ID of txtSearchName but when page is rendered it is adding extra string from master page.
How can I stop this? I have to use master page so don't say not to use master page :)
Why is it doing that?
Update
While Googling and Binging I found that I can use Control.ClientID in this case so looking into it.
Update 2
As suggested below to add ClientIDMode="static" in the html of control or add it in page directive. What it does is, it keeps the ID static to txtSearchName but problem is this,
<input name="ctl00$cpMainContent$txtSearchName" type="text" id="txtSearchName" />
Here name is still using ctl00 and the code I showed above,
string strSearch = myRequest["txtSearchName"]
it still won't work because nvc collection is either searchable by index or name not the id directly.
==============
You need to add a ClientIDMode="Static" to the html of the textbox:
<asp:TextBox ID="txtSearchName" runat="server" ClientIDMode="Static" />
It happens to prevent duplicate ID's. Usually it happens when you use master pages as it contains nested pages
If you want all controls with ClientIDMode="Static", you can put it in the page header of the master file.
<%# Page Language="C#" ClientIDMode="Static" %>
If you are posting to another page that uses the same master page (called SiteMaster in my case), the name of the textbox should be same the same.
string val = Request[((SiteMaster)Master).txtSearchName.UniqueID];
If you're NOT posting to a page with the same master, well, then are you using the viewstate for the textbox at all since you're posting to another page? If not, just make the control a non asp.net control:
<input type="text" name="txtSearchName"/>
If you are using viewstate and posting to another page with a different master page, well, you should use PreviousPage.
Little late here. Appreciate #aquinas and #rudeovski ze bear. Interesting and good answers.
I'd same issue and I solved it differently.
In fact, I used a public Interface.
public interface ISearch
{
string SearchText { get; }
}
Then implement ISearch interface in two aspx page say One.aspx and Two.aspx classes.
--One.aspx-- (Where I'v added TextBox1, and Button1 and set Button1.PostBackUrl="~/Two.aspx")
public partial class One : System.Web.UI.Page , ISearch
{
public string SearchText
{
get
{
return TextBox1.Text;
}
}
}
--Two.aspx--
public partial class Two : System.Web.UI.Page, ISearch
{
protected void Page_Load(object sender, EventArgs e)
{
ISearch search = (ISearch) PreviousPage;
Label1.Text = search.SearchText;
}
public string SearchText
{
get
{
throw new NotImplementedException();
}
}
}
If your try to access the input element value in code behind on post back instead of for example:
var emailAddress = Request.Form["ctl00$ctl00$ctl00$ContentContainer$MainContent$MainContent$ContentBottom$ProfileFormView$emailaddress1"];
Use
var emailAddressKeyName = Request.Form.AllKeys.FirstOrDefault(a => a.Contains("emailaddress1"));
var emailAddress = Request.Form[emailAddressKeyName];
I have a custom .ascx control and would like to set one of it's properties using code. In the .aspx I have this:
<uc1:CustomContent ID="bunchOfContent" runat="server" contentPayload='<%# getRegionID() %>' />
In the codebehind I have:
public partial class Region : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
... things
}
public string getRegionID()
{
//return "region_" + Request["region"];
return "thevalueIwant";
}
However, the value I want is not populated and the code is not invoked (breakpoints are not triggered).
What am I doing wrong? I've tried various changes like changing the quotes from " to ' to no quotes at all. Also I've used <%= instead of <%# but no luck. Thanks!
In the Page_Load method, you can do:
bunchOfContent.contentPayload = getRegionID();
The reason why <%# ... %> did not work is because that's the form you use for databinding. In order for the code you put in there to be executed, you need to call the DataBind() method somewhere. And as for <%= ... %>, that's not suitable for setting a server control property, it simply is a short form of <% Response.Write(...) %>.
In my code i create a HyperLinkField object. Depending on a database field value, i want to set the NavigateUrl property. This is my problem, i don't know how.
With:
objHF.DataNavigateUrlFields = new[] { "id", "Stype" };
i get my database field. Now i want to check the Stype value. Depeding on this value i want to set the page where to navigate to. How can i do this??
At the end i set my datasource to the gridview and after that i call the bind() method.
I hope someone can help me out
Make the HyperLinkField a TemplateField, and set the NavigateUrl of the resulting HyperLink (in markup) to something like
<%# myUrlFunction(Eval("id"), Eval("stype")) %>
Next create a corresponding function in the .cs file:
private string myUrlFunction(object id, object stype)
{
return "mypagename.aspx?whatever=" + id.ToString() +
"&youwanttodo=" + stype.ToString();
}
try this way
<%# this.myUrlFunction(Eval("id"), Eval("stype")) %>
this is worked