my question is related to the fileupload control.I am loading my usercontrollers dynamically via ashx handler.so far so good.but when I put
<ext:FileUploadField runat="server" />
my ashx handler give me error which tell me null reference .
I am doing this with the text,textfield elements ,in that case, no problem ,my user control loading without no problems.
(<ext:TextField runat="server" FieldLabel="deneme"></ext:TextField>)
someone tell me where is the problem .
here is the my ashx handler,
public void ProcessRequest(HttpContext context)
{
string mainTabPnl = context.Request["container"];
string url = context.Request["url"];
string id = context.Request["id"];
Ext.Net.Panel pn = new Ext.Net.Panel()
{
Title = "MY TITLE",
Closable = true,
Layout = "Fit",
Height=500,
ID=id,
Items = {
new UserControlLoader{
Path=url
}
}
};
pn.AddTo(mainTabPnl);
new DirectResponse().Return();
}
ext:FileUploadField
should be placed inside html form tag
<form>
<ext:FileUploadField
</form>
Related
My current scenario is I retrieved the HTML of a page using the following method.
readStream = New StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet))
Dim fullString As String = readStream.ReadToEnd()
I did further formatting of the HTML before setting it to the innerHtml of my div.
displaystring = Regex.Replace(fullString, "<div.*?>", "<div>")
displaystring = Regex.Replace(fullString, "<span.*?>", "<span>")
displaystring = Regex.Replace(fullString, "<table.*?>", "<table>")
For example, I have a part of HTML code which is
<a>Brazil</a>
And I have tried fullstring = Regex.Replace(fullstring, "<a>Brzail</a>", <asp:Linkbutton name="lnkTest" runat="server"). And I realized it cannot work because ASP controls cannot be appended as string.
How can I control.Add just after <a>Brazil</a>? Any other suggestions are welcome too.
You cannot add ASP.Net Server control like this. You can use html control anchor tag or button and on click of this you can make an AJAX call.
Sample code will be like this
fullstring = Regex.Replace(fullstring, "<a>Brzail</a>", "<a href='#' onclick='clickMe'>Link</a>")
In Server side C# you can write a page method
like `
[PageMethod]
public static string MyMethod()
{
//Your logic
return "";
}
`
In javascript
function cickMe()
{
$.ajax({
url: "Sample.aspx/MyMethod",
success: function(data){
//your logic
}
});
}
I've looked at several similar questions to this one and right now I am trying to use the FindControl method without success.
My Web Forms application has several master pages. Common to all master pages is a search box and button in a nav user control at the top. I'm trying to grab the search term entered on the SearchResults page:
HtmlGenericControl topNavDiv = (HtmlGenericControl)Master.FindControl("topNavDiv");
Control topNav = (UserControl)Page.FindControl("topNav");
if (topNav != null)
{
TextBox searchBox = topNav.FindControl("searchBox") as TextBox;
if (searchBox != null)
{
Response.Write(searchBox.Text.Trim());
}
else
{
resultsPanel.Visible = false;
messagePanel.Visible = true;
}
}
In the first line, the topNavDiv variable is null. I was considering accessing the user control via a master page property, but with several different master pages I don't know how to determine the id of the master page as the search could be initiated from anywhere in the site...
UPDATE:
I was able to grab the topNav div, searchBox textbox as follows:
Control topNav = (UserControl)Master.FindControl("topNav");
if (topNav != null)
{
TextBox searchBox = topNav.FindControl("searchBox") as TextBox;
if (!String.IsNullOrEmpty(searchBox.Text))
{
Response.Write(searchBox.Text.Trim());
}
else
{
resultsPanel.Visible = false;
messagePanel.Visible = true;
}
}
The only problem is that the search box text entered is not being persisted.
If you need to keep the data out of the query string for some reason you could use a Property on your MasterPage.cs file.
public string SearchTerm
{
get
{
return searchBox.Text;
}
}
Then you can use that wherever you need to like this:
MasterPage master = (MasterPage)this.Master;
master.SearchTerm;
Since this is an Intranet site, I was able to utilize a query string parameter to obtain the search term as follows:
Nav with Search Box User Control:
<ul class="navbar-form navbar-left">
<li>
<asp:TextBox ID="searchBox" class="form-control col-lg-8"
placeholder="Search" runat="server"></asp:TextBox>
<asp:Button ID="searchButton" CssClass="btn btn-warning" Text="Search"
runat="server" OnClick="searchButton_Click" />
</li>
</ul>
User Control Code-Behind:
protected void searchButton_Click(object sender, EventArgs e)
{
Response.Redirect("~/Search/SearchResults.aspx?term="+searchBox.Text.Trim());
}
Search Results Page Code-Behind:
if (!Page.IsPostBack)
{
if (!String.IsNullOrEmpty(Request.QueryString["term"]))
{
term = Request.QueryString["term"].ToString();
Response.Write(term);
}
else
{
resultsPanel.Visible = false;
messagePanel.Visible = true;
}
}
What I would really like to know is if it is programmatically possible to determine in a page's code-behind, the identity of the master page of the requesting page?
I am using AsyncFileUpload (ajaxToolkit) control for uploading image file from registration page. uploaded file content are store into DB. So I need to show my uploaded file in asp:image control by httphander like <asp:image id="imgLogo" runat="server" ImageUrl="Images.aspx/id=12" />. So how to do this.
Assuming you are storing the image as a byte[] in DB;
var data = new byte[1]; //Replace this with your values from DB
var mimeType = "application\pdf"; //Replace this with your values from DB
response.ContentType = mimeType ;
response.BinaryWrite(data);
This code should be placed in page_load in images.aspx after you have retrieved the values from the DB.
Your image page handler page_load method will be
Images.aspx
protected void Page_Load(sender s, eventagrs e){
var imagecontent= new byte[XXXX]; // Read DB content as bytes for the passed Id
response.ContentType = 'jpeg/gif/anything' ;
//this should be a valid MIME type saved in database
response.BinaryWrite(imagecontent);
}
Edit:
From your comments you are trying to update the image tag src value
from codebehind using Asp.Net Ajax.
If you want to do this, first make sure your page has access to view state
information about those image tags. This is not a big deal, you simply
wrap the image tags container panel/div with update panel.
So your ajax request will send the information about those viewstate and
push the partial update for those image container panel also.
I have reviewed many site and I got answer of this question..
http://www.mikeborozdin.com/post/AJAX-File-Upload-in-ASPNET-with-the-AsyncFileUpload-Control.aspx
<ajaxToolkit:AsyncFileUpload ID="afuCompanyLogo" runat="server"
OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete"
UploaderStyle="Modern" UploadingBackColor="#CCFFFF"
ThrobberID="myThrobber"
onuploadedcomplete="afuCompanyLogo_UploadedComplete" />
<asp:Image ID="imgCompanylogo" CssClass="imgCompanylogo" runat="server" Height="80px" Width="80px" AlternateText="" />
protected void afuCompanyLogo_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if(afuCompanyLogo.HasFile)
{
FileManagementEntity fileManagementEntity = new FileManagementEntity();
FileManagement fileManagement = fileManagementEntity.Create();
fileManagement.FileContentType = afuCompanyLogo.ContentType;
fileManagement.FileContent = afuCompanyLogo.FileBytes;
fileManagement.Size = afuCompanyLogo.FileBytes.Count();
fileManagement.OriginalName = afuCompanyLogo.FileName;
fileManagementEntity.Save(fileManagement);
ViewState["logoID"] = fileManagement.FileManagementID;
imgCompanylogo.ImageUrl = "Image.aspx?id=" + fileManagement.FileManagementID.ToString();
ScriptManager.RegisterClientScriptBlock(afuCompanyLogo, afuCompanyLogo.GetType(), "img", "top.document.getElementById('" + imgCompanylogo.ClientID + "').src='Image.aspx?id=" + fileManagement.FileManagementID + "';", true);
}
}
i need open pop up in asp.net using post Method and window.open to rezise te new windows.
my code:
Open the pop up:
function mdpbch(URL) {
child = window.open(URL, "passwd","dependent=1,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=475");
child.location.href = URL;
if (child.opener == null) {
child.opener = window;
}
child.opener.name = "opener";
}
URL:
function PagoEnLinea(Banco)
{
switch(x){
case "BCH":
document.frmEnvia.action = SERV + "/llamacom.asp";
url = SERV + "lamacom.asp
alert(url);
mdpbch(url);
document.frmEnvia.submit();
break;
}
}
ASPX:
<body>
<form id="frmEnvia" runat="server" name="formulario" method="post" target="_blank">
<div style="visibility:hidden;">
<asp:TextBox ID="txtXml" runat="server" Visible="true" />
</div>
.....
</body>
on page load (code behind) i create a xml string and put it in the textbox txtXml.
i need use post method becose the server validate te method, and window.open becose need customize the pop up
thanks
I think you should manipulate the object:
parentWindow
Inside the document object; before you submit the form, something like this:
switch(x){
case "BCH":
document.frmEnvia.action = SERV + "/llamacom.asp";
url = SERV + "lamacom.asp
alert(url);
mdpbch(url);
//here you manipulate the parentWindow element
document.parentWindow.scrollbars... (add the attributes you need)
//--
document.frmEnvia.submit();
break;
}
Since you are setting the name of the popup to passwd, you should then be able to set the target attribute of the form to passwd.
So the only change needed is the following:
<form ... target="passwd">
Good day everyone,
I am building a page in ASP.NET, and using Master Pages in the process.
I have a Content Place Holder name "cphBody" in my Master Page, which will contain the body of each Page for which that Master Page is the Master Page.
In the ASP.NET Web page, I have a Content tag (referencing "cphBody") which also contains some controls (buttons, Infragistics controls, etc.), and I want to access these controls in the CodeBehind file. However, I can't do that directly (this.myControl ...), since they are nested in the Content tag.
I found a workaround with the FindControl method.
ContentPlaceHolder contentPlaceHolder = (ContentPlaceHolder) Master.FindControl("cphBody");
ControlType myControl = (ControlType) contentPlaceHolder.FindControl("ControlName");
That works just fine. However, I am suspecting that it's not a very good design. Do you guys know a more elegant way to do so?
Thank you!
Guillaume Gervais.
I try and avoid FindControl unless there is no alternative, and there's usually a neater way.
How about including the path to your master page at the top of your child page
<%# MasterType VirtualPath="~/MasterPages/PublicUI.Master" %>
Which will allow you to directly call code from your master page code behind.
Then from your master page code behind you could make a property return your control, or make a method on the master page get your control etc.
public Label SomethingLabel
{
get { return lblSomething; }
}
//or
public string SomethingText
{
get { return lblSomething.Text; }
set { lblSomething.Text = value; }
}
Refers to a label on the master page
<asp:Label ID="lblSomething" runat="server" />
Usage:
Master.SomethingLabel.Text = "some text";
//or
Master.SomethingText = "some text";
Rick Strahl has a good explanation (and sample code) here - http://www.west-wind.com/Weblog/posts/5127.aspx
Nothing to do different. Just write this code on child page to access the master page label control.
Label lblMessage = new Label();
lblMessage = (Label)Master.FindControl("lblTest");
lblMessage.Text = DropDownList1.SelectedItem.Text;
I use this code for acess to files recursively:
/// <summary>
/// Recursively iterate through the controls collection to find the child controls of the given control
/// including controls inside child controls. Return all the IDs of controls of the given type
/// </summary>
/// <param name="control"></param>
/// <param name="controlType"></param>
/// <returns></returns>
public static List<string> GetChildControlsId(Control control, Type controlType)
{
List<string> FoundControlsIds = new List<string>();
GetChildControlsIdRecursive(FoundControlsIds, control, controlType);
// return the result as a generic list of Controls
return FoundControlsIds;
}
public static List<string> GetChildControlsIdRecursive(List<string> foundControlsIds, Control control, Type controlType)
{
foreach (Control c in control.Controls)
{
if (controlType == null || controlType.IsAssignableFrom(c.GetType()))
{
// check if the control is already in the collection
String FoundControl = foundControlsIds.Find(delegate(string ctrlId) { return ctrlId == c.ID; });
if (String.IsNullOrEmpty(FoundControl))
{
// add this control and all its nested controls
foundControlsIds.Add(c.ID);
}
}
if (c.HasControls())
{
GetChildControlsIdRecursive(foundControlsIds, c, controlType);
}
}
Hi just thought i'd share my solution, found this works for accessing a 'Control' that is inside an < asp:Panel> which is on a 'ContentPage', but from C# code-behind of the 'MasterPage'. Hope it helps some.
add an < asp:Panel> with an ID="PanelWithLabel" and runat="server" to your ContentPage.
inside the Panel, add an < asp:Label> control with ID="MyLabel".
write (or copy / paste the below) a function in your MasterPage Code-behind as follows: (this accesses the label control, inside the Panel, which are both on the ContentPage, from the Master page code-behind and changes its text to be that of a TextBox on the Master page :)
protected void onButton1_click(object sender, EventArgs e)
{
// find a Panel on Content Page and access its controls (Labels, TextBoxes, etc.) from my master page code behind //
System.Web.UI.WebControls.Panel pnl1;
pnl1 = (System.Web.UI.WebControls.Panel)MainContent.FindControl("PanelWithLabel");
if (pnl1 != null)
{
System.Web.UI.WebControls.Label lbl = (System.Web.UI.WebControls.Label)pnl1.FindControl("MyLabel");
lbl.Text = MyMasterPageTextBox.Text;
}
}