Check This Example: .aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test-file-upload1.aspx.cs" Inherits="test_file_upload1" %> <!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 language="javascript" > function PostBack(t) { __doPostBack('Test',t.value); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server"> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> </asp:DropDownList> </div> </form> </body> </html> .cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; public partial class test_file_upload1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DropDownList1.Attributes.Add("onchange", "PostBack(this);"); if (IsPostBack) { string strControlName = ""; strControlName = Request.Params.Get("__EVENTTARGET"); if (strControlName == "Test") { string strArgument = ""; strArgument = Request.Params.Get("__EVENTARGUMENT"); Update(strArgument); } } } private void Update(string strTest) { Response.Write("You have selectecd: " + strTest); } }
amitabha123
Posts
-
Calling a serverside method by __doPostBack()? -
Control value from one page to the otherLucBite wrote:
I want to use textbox value(text) in another asp.net page. eg. displaying txtName.Text from page1 in lblName in the next page OR use that value as a parameter passed to method calling under a button in the next page.
You can use session. Alternatively you can use PostBackURL features of .Net. For ex: Page1.aspx: ----------- <asp:textbox id="txt1" runat="server" ></asp:textbox> <asp:button id="Button1" postbackurl="~/page2.aspx" runat="server" text="Button" /> Page2.aspx: ----------- add this line under page directive: <%@ previouspagetype virtualpath="~/page1.aspx" %> Page2.aspx.cs: ----------- TextBox txt = (TextBox)PreviousPage.FindControl("txt1"); Response.Write( txt.Text);
-
how to upload the file on another page?You can't change the text in the file upload control, and you cannot pass that text to another form, or get another form to read the file. But you can send the file as Stream. Here is an example. I used two page test-file-upload1.aspx ( from where user chhose the file to upload) and test-file-upload2.aspx( where the actual upload happens). test-file-upload.aspx.cs: ------------------------- protected void Button1_Click(object sender, EventArgs e) { Stream s = FileUpload1.FileContent; Session["test"] = s; Response.Redirect("test-file-upload2.aspx"); } test-file-upload.aspx.cs: ------------------------- string strPhysicalPath = ""; protected void Page_Load(object sender, EventArgs e) { strPhysicalPath = Server.MapPath("~/test-image/"); Stream fsInput = (Stream)(Session["test"]); byte[] bufferInput = new byte[fsInput.Length]; fsInput.Read(bufferInput, 0, bufferInput.Length); fsInput.Close(); //------------You can change the extension as original by sending the original extension in session FileStream fsOutput = File.Create(strPhysicalPath + "test.jpg"); fsOutput.Write(bufferInput, 0, bufferInput.Length); fsOutput.Close(); fsOutput.Dispose(); Response.Write("OK "); } I hope it solves your problem. Please mark it as answer if helps.
-
Problem in scriptJust put the javascript code in a div with visibility false. Now depending on the condition make the visibility of that particular div true. Please mark it as answer if it helps.