Click here to Skip to main content
15,916,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i want to call Response.Redirect(Request.RawUrl); once i complete with below code(saveFile) so that all the selection get reset.

C#
private void saveFile(StringWriter sw, string fileName)
{
    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "application/vnd.ms-excel";
    string attachment = "attachment; filename=" + fileName + " " + DateTime.Now.ToString() + ".xsd";
    Response.AddHeader("content-disposition", attachment);
    Response.Charset = "";
    this.EnableViewState = false;

    Response.Write(sw.ToString());
    Response.End();

}


i want to reset the dynamic grid dropdown once the file is get saved.
help
thanks :)
Posted

1 solution

No you cannot. Response.End() ends all responses for the page. So any code placed after that will not have any effect on the page.

Instead , remove the Response.End() and use only Response.Redirect(). It will achieve the result you want.

On other thoughts, you can programatically set the selectedIndex property of the dropdowns to default or clear the textboxes like this

C#
TextBox1.Text = String.Empty;
DropDownList1.SelectedIndex = -1;
 
Share this answer
 
Comments
sawant parag 28-Mar-12 8:11am    
i am using the Dynamic genrated DropDown, my dropdown get binded on Onload event of the DropDown in grid view. so i am not able to make selectedindex as -1, if you any other method other then specified above let me know.

i used Response.Redirect(Request.RawUrl);
instead of // Response.End();

but i am not able to save the file, i am not able to achive the task .
help
bbirajdar 28-Mar-12 9:25am    
When you are using the dynamically generated dropdown, then the selections will automatically get reset on click of submit button. You dont need to clear it.

And if can bind a dropdown to the data in codebehind at runtime, you should be able to set the selectedIndex to -1 at runtime as well.. Right ??
sawant parag 28-Mar-12 10:58am    
i am using Dynamic Drop down of gridview , when i select one of the drop then it try to save the select item by using the above save function and in this save function i am ending the response as it is shown above.
i am not using the submit button so it is not getting cleared automatically.
as drop down is an gridview , i am not able to directly save its selectedIndex to -1.
bbirajdar 28-Mar-12 13:32pm    
You are not explaining on which event of Dropdown you are trying to access the dropdown slected item.

Rework on your complete code

Here is the sample code for your reference .

http://webthingsconsidered.blogspot.in/2005/09/dropdownlist-inside-gridview-or.html
sawant parag 29-Mar-12 2:32am    
hi below is my gridview control code.

<asp:GridView ID="grdModels" runat="server" AutoGenerateColumns="false" AllowSorting="true"
AllowPaging="true" HeaderStyle-CssClass="row0" Width="100%" HeaderStyle-VerticalAlign="Top"
RowStyle-CssClass="row1" RowStyle-VerticalAlign="Middle" DataKeyNames="Engine_Version,Model_Version,Model_Name"
OnSorting="grdModels_Sorting">
<columns>
<asp:TemplateField SortExpression="Model_Name" HeaderStyle-VerticalAlign="Top" HeaderText="Model Name">
<itemtemplate>
<asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='<%# "Model_ValidateFiles.aspx?EngineVersion=" + Eval("Engine_Version") + "&ModelName=" + Eval("Model_Name") + "&ModelVersion=" + Eval("Model_Version")+"&action=validate&modeltab=Model_Validate" %>'
Text='<%# Eval("Model_Name")%>'>


<asp:BoundField HeaderText="Model Version" DataField="Model_Version" SortExpression="Model_Version" />
<asp:BoundField HeaderText="Author" DataField="Created_By" SortExpression="Created_By" />
<asp:TemplateField HeaderStyle-VerticalAlign="Top" HeaderText="Create <BR> Date & Time"
SortExpression="Created_On">
<itemtemplate>
<%# Eval("Created_On", "{0:g}")%>

<asp:TemplateField HeaderStyle-VerticalAlign="Top" HeaderText="Publish Due <BR> Date & Time"
SortExpression="Published_Date" ItemStyle-Width="100">
<itemtemplate>
<%#Eval("Published_Date", "{0:g}")%>

<asp:BoundField HeaderText="Reviewer" DataField="Last_Reviewed_By" SortExpression="Last_Reviewed_By" />
<asp:TemplateField HeaderStyle-VerticalAlign="Top" HeaderText="Last Reviewed Date & Time"
SortExpression="Last_Reviewed_On" ItemStyle-Width="100">
<itemtemplate>
<%#Eval("Last_Reviewed_On","{0:g}")%>

<asp:BoundField HeaderText="ModelStatus" DataField="Model_Status" Visible="false"
SortExpression="Model_Status" />
<asp:TemplateField HeaderText="Actions">
<itemtemplate>
<asp:DropDownList ID="ddModelActions" runat="server" CssClass="largeSelectBoxContainer_1 handCursor"
Style="z-index: 999; padding: 4px;" AutoPostBack="true" OnLoad="ddModelActions_Load"
OnSelectedIndexChanged="ddModelActions_IndexChanged">






and below is the event on which i am trying to access the selected item .

protec

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900