|
Can you provide code snippet for the same??
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi
I am using Microsoft's MVC design pattern and I have a method in my controller, which sets the data source of a gridview. Whilst I can bind all the other values in the gridview, I am stuck setting 4 hyperlinks. The hyperlinks need to work in the explanation given in the link below: http://forums.asp.net/p/542979/3077895.aspx for forcing downloads to keep the location of where files are saved to private, which I want set in the controller.
To fully explain what I am doing, in my controller for the gridview, I am setting the gridview's data source using ICollection, which is an object containing results from a query. From this collection, I extract a value which has the name of a folder which contains a number files. So, what I have done is to cast my collection to a object, to get folder name and then use a foreach loop to get each folder name. Then to get the files inside each folder, I use Directory.GetFiles, which returns a string array - I wrote string[] files = Directory.GetFiles(ConfigurationManager.appsettings["filepath"]+folderName); . I have set 4 properties for each Hyperlink I want to set.
It is at this point where I am stuck, because even though I can get to the files, I am unable to set the Hyperlinks to these files. Each time I try an set the NavigateUrl property, I get the error message Object not set to an instance of an object. Plus, I have two other issues to resolve:
1) Even though there are 4 hyperlinks, not every hyperlink will be set. In other words, if there are only two files in the folder, I only want to set the appropriate hyperlinks. So, how can I iterate through the string array, and get each value inside the array to do a check?
2) When I set my Hyperlinks in my controller, how do I simply pass the file and keep the file's actual storage location hidden as given in the link http://forums.asp.net/p/542979/3077895.aspx
Thanks
|
|
|
|
|
When you say "Microsoft's MVC design pattern" you mean you have created an MVC application correct? What version? If you are using a MVC application then you have control of the output and formatting in the markup of view or you can set the ViewData or model appropriately. Perhaps if you showed some of what you are doing it would be clear.
Also, as note, if you are including a URL it is customary to make it a hyperlink so people can navigate without copy & paste
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hi iam using asp.net with c#
if (FileUpload1.HasFile)
{
FileInfo branchinfo = new FileInfo(FileUpload1.PostedFile.FileName.Trim());
byte[] branchcontent = new byte[branchinfo.Length];
FileStream branchstream = branchinfo.OpenRead();
branchstream.Read(branchcontent, 0, branchcontent.Length);
branchstream.Close();
cmdsave.Parameters.AddWithValue("@BranchPicture", (branchcontent == null? System.DBNull.Value: branchcontent));
}
else {
cmdsave.Parameters.AddWithValue("@BranchPicture",DBNull.Value);
}
but it is giving error
Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'byte[]'
can you correct the code where iam going wrong
|
|
|
|
|
You should try...
branchcontent.ToString() == null? null : branchcontent
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
hi iam using asp.net with c#
iam using dropdownlist control in update panel control but no selectedindexchange event is firing can you make a change in my code which helps me
<asp:UpdatePanel ID="pannelupdate" runat="server" ><ContentTemplate><asp:DropDownList ID="ddlconnectivity" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlconnectivity_SelectedIndexChanged"><asp:ListItem Value="DSL">DSL</asp:ListItem><asp:ListItem Value="Connect">Connect</asp:ListItem><asp:ListItem Value="Not Available">Not Available</asp:ListItem><asp:ListItem Value="Others">Others</asp:ListItem></asp:DropDownList></ContentTemplate><Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlconnectivity" EventName="SelectedIndexChanged" />
</Triggers></asp:UpdatePanel>
protected void ddlconnectivity_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlconnectivity.SelectedValue == "Dsl" || ddlconnectivity.SelectedValue == "Connect" || ddlconnectivity.SelectedValue == "Others")
{
txtconnectaccount.Visible=true;
}
else {
txtconnectaccount.Visible = false;
}
}
when iam selecting any item it is not performing any action and giving message use EnableEventValidation=true in page directive , i have done like this also but even though it is not performing any action. can you help correct the code which helps me
|
|
|
|
|
|
hi it is giving error when iam selecting items from drop down list no action is performing
error
======
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
code
====
<asp:UpdatePanel ID="pannelupdate" runat="server" UpdateMode="Conditional" ><ContentTemplate><asp:DropDownList ID="ddlconnectivity" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlconnectivity_SelectedIndexChanged"><asp:ListItem Value="DSL">DSL</asp:ListItem><asp:ListItem Value="Connect">Connect</asp:ListItem><asp:ListItem Value="Not Available">Not Available</asp:ListItem><asp:ListItem Value="Others">Others</asp:ListItem></asp:DropDownList></ContentTemplate><Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlconnectivity" EventName="SelectedIndexChanged" />
</Triggers></asp:UpdatePanel>
protected void ddlconnectivity_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlconnectivity.SelectedValue == "Dsl" || ddlconnectivity.SelectedValue == "Connect" || ddlconnectivity.SelectedValue == "Others")
{
txtconnectaccount.Visible=true;
}
else {
txtconnectaccount.Visible = false;
}
}
action is not performing can you correct my code where iam going wrong.
|
|
|
|
|
|
try this ....
<asp:AsyncPostBackTrigger ControlID ="YourDropDownName" EventName ="YuorEventName" />
|
|
|
|
|
I have created a web chat application, to get to the webchat user has to login using his username and password. When I was developing my application the redirection sometimes was working, and sometimes not, I didn't really know why, but I wasn't bothered about that then.
Now I wanted to access my webpage by using IIS, I was following this tutorial:
http://www.codeproject.com/KB/aspnet/IIS7ASPNet.aspx
The login page is with this adress: http://localhost/Smiths1/Default.aspx
and it should redirect me to:
http://localhost/Smiths1/SmithChat.aspx?roomID=14
but I don't know why it redirects me to:
http://localhost/Smiths1/Default.aspx?ReturnUrl=%2fSmiths1%2fSmithChat.aspx%3froomID%3d14&roomID=14
and I can't get to the webchat (I still see the login page, but I assume it;s only because the name of it is Default.aspx).
The instruction in login page looks like that:
<code>Response.Redirect("SmithChat.aspx?roomID=14", true);</code>
I don't know what causes whis "error", could someone help me please?
|
|
|
|
|
You problem is not clear. please rephrase your question.
|
|
|
|
|
I think I should start with showing you my code in the login page (I'm using prepared asp login component):
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
SmithChatDataContext data = new SmithChatDataContext();
var user = (from u in data.Users
where u.Username == Login1.UserName
&& u.Password == Login1.Password
select u).SingleOrDefault();
if (user != null)
{
e.Authenticated = true;
Session["ChatUserID"] = user.UserID;
Session["ChatUsername"] = user.Username;
Response.Redirect("SmithChat.aspx?roomID=14", true);
}
else
{
e.Authenticated = false;
}
}
}
and when I run the page from the Visual Studio, it goes to the login page, when I'm trying to login - sometimes it redirects me to the webchat as it should, and sometimes the link after authentication looks like that:
http://localhost:49786/Smiths/Default.aspx?ReturnUrl=%2fSmiths%2fSmithChat.aspx%3froomID%3d14&roomID=14
and I'm still on the login page. I don't know what is wrong.
Anyway, I tried to deploy my application using IIS, so I followed the tutorial which I mentioned about before, and my login page is accessible (http://localhost/Smiths1/Default.aspx) However, after authentication it stays on the login page and the link again looks like that:
http://localhost/Smiths1/Default.aspx?ReturnUrl=%2fSmiths1%2fSmithChat.aspx%3froomID%3d14&roomID=14
|
|
|
|
|
I think it is redirecting to default page because
it is not finding SmithChat.aspx page on it's path.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
try this
Response.Redirect("SmithChat.aspx?roomID=14", false);
|
|
|
|
|
Thanks, but I've tried that already. It's not redirecting anywhere at all when this boolean is set to false (stays on the default.aspx). I still can't figur out what's wrong
|
|
|
|
|
I have an ordering site with a requirement where I need to allow a user to upload a file and while that file is uploading, allow them to continue on in the page flow. On each page, I wish to be able to check on the status of the file uploading and provide feedback to the user on the status of the upload, such as a progress bar.
I'm looking for ideas on how to begin a file upload and then allow for page navigation without ending the upload. ASP.Net / AJAX are good to use, but not Silverlight
|
|
|
|
|
Interesting problem. The first thing that comes to mind is to use an iframe for the navigation so the file upload is taking place in one page while other pages are displayed in the iframe.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Not a bad idea in general, but unfortunately won't work for my purposes. We cannot place the main page content into an iframe for navigation, it could create a lot of problems for us.
Any other ideas?
|
|
|
|
|
As I'm sure you know the difficulty is keeping the uplaod active while navigating to another page. The thing the pops to mind (pun intended ) is a popup window to handle the upload, however that could be blocked by browser settings, etc.
Although its just a variation on the the same idea you could use ajax calls to refresh the content.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
What if you just open a new pop window and allow the users to upload the files in the popup window
For whowing the progress... There are some solutions for that, just google it
Alexei Rodriguez
|
|
|
|
|
I have an application built using classic asp. I built a page using asp .net (C#) and need to retrieve parameter values passed from the asp page.
Some of them are working - when I use code like MyControl = Request.Form["cmbDepartmentID"];
But for unknown reason - the others are not working.
So, I tried to create a Session object in the asp page, and retrieve it in the asp.net.
In the asp for example - Session("Param") = value
And in the asp.net - MyParam = Session["Param"].ToStrng();
But it doesn't recognize the session object.
What is the way to do it?
The asp page is a huge mumbo-jumbo of vbscript, javascript, html etc. that I don't follow the flow clearly. But I know querystring is not an option here.
Thanks.
|
|
|
|
|
ASP and ASP.Net do not share the same session on the same server by default. Microsoft has a way to implement session sharing[^] but I don't think a lot of people have had good experiences with it.
Have you done any debugging to output all of the Request.Form items to see if they are being posted? I can't remember if Request.Form in ASP.Net is case sensitive or not.
|
|
|
|
|
Hi Gray,
Yes I tried outputting all of them, and some are not being passed to the asp.net. Thats why I can't retrieve them. When I did that - I used the same case wording.
I could try the Session sharing technique you pointed to, but it looks like overkill.
I'll go back and dig further - and let you know.
Thanks.
|
|
|
|