|
Hello all,
In my ASP.Net application, i am transferring GridView contents to a excel file. I am using following code:
string attachment = "attachment; filename=MakeList.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
It was working fine, but as soon as i put this code in try-catch block, i am getting this error:
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
If i remove try-catch block, it again works fine.
Can anyone tell me whats the problem? Am i miising something?
Thanks,
Nagendra.
|
|
|
|
|
|
I tried the solution. Now i am not getting any exception but now instead of GridView contents, the whole WebPage is copied in excel file.
I want only GridView contents in excel file.
|
|
|
|
|
What you have done?
I think you removed Response.End().
|
|
|
|
|
Yes, as mentioned in that post, i used "HttpContext.Current.ApplicationInstance.CompleteRequest()" in place of Response.End()
|
|
|
|
|
Hi All My Friends,
I Have 2 problems in a javascript.
1: I am not getting the Item Count Of Dropdown List.
2: I am calling javascript on Button "OnClientClick" event,then also onclick event is fired even script returning false.
Hav a look on Script
function validate()
{
if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex == 0) {
alert("Select a Category name !")
document.getElementById("<%=ddlCategories.ClientID%>").focus()
return false;
}
else if (document.getElementById("<%=txtText.ClientID%>").value == "") {
alert("Please fill the Message field !")
document.getElementById("<%=txtText.ClientID%>").focus()
return false;
}
else {
if (SubcategoryCount > 0) {
if (document.getElementById("<%=ddlCategories.ClientID%>").selectedIndex != 0 && document.getElementById("<%=ddlSubCategories.ClientID%>").selectedIndex == 0) {
alert("Select a Sub-Category name !")
return false;
}
}
}
}
|
|
|
|
|
Sachin Dubey wrote: if (SubcategoryCount > 0) {
Where you got this SubcategoryCount from?
Its good if you can make your code little bit readable to the forum readers.
|
|
|
|
|
That is only i asked in first question.. I Have ddlSubCategories in Page
|
|
|
|
|
Sachin Dubey wrote: That is only i asked in first question
that i know.
What i am asking is, in your code you have a line of code like,SubcategoryCount>0,
Whats SubcategoryCount?Is it a global variable?How you are assigning value for that?
|
|
|
|
|
That is not any Variable...That is just i written...
But I want to Use ddlSubcategories.Items.Count in place of SubCategoryCount..
But I Am not Getting the value...
Actually if user doesnt select category then Select Category alert will Prompt..If User Selected Category And There is no Subcategory of that then we allow him to proceed...But if that category has some Sub Categories then its must to Select SubCategory...
Thats what i Want in Else Condition u see...
|
|
|
|
|
Sachin Dubey wrote: That is not any Variable...That is just i written...
How we know its simply written.
Ok.Try ddlSubCategory.options.length
|
|
|
|
|
Thanks Arun I Got The count By :
if (document.getElementById("<%=ddlSubCategories.ClientID%>").options.length > 1)
Now its showing the message also...But Its Saving the record ...
My Code of Button is:
<asp:button id="btnSave" runat="server" text="Save" width="100px" onclientclick="javascript:validate();" onclick="btnSave_Click">
After reading that script it reading On_click event Code...
How to Tackele that..
|
|
|
|
|
Sachin Dubey wrote: OnClientClick="javascript:validate();"
Instead try this,
OnClientClick="return validate();"
|
|
|
|
|
Hey Arun... It Works...
Thanks A Lot....
|
|
|
|
|
Hi,
I am having datatable .. i want to add columns to that , i need to add same column once again ... is it possible ???
if it possible pls let me know the right path ...
for i=0 to 10
datatable.column.add("values to be added")
next
note: it throughs excepttion like , column already exist
thanks,
sekannak...
kannak
|
|
|
|
|
sekannak wrote: . i want to add columns to that , i need to add same column once again
I don't think that your idea is good.If you are trying to add same column again you'll get that error.What you are trying to acheive by adding same column again?
|
|
|
|
|
As you have found, column names must be unique. The values you store in the column can be the same of course.
only two letters away from being an asset
|
|
|
|
|
hi
i have created a ASP.NET web application.
I have 3 web forms (.aspx) pages in that.I have 2 hyperlinks in one page.when i click on that link,the repective page should load.I am able to display page from link(without frames),but link disappears(since it's another page).
So can anybody tell me how to create frames,so that page will be displayed in some area and hyperlink will be visible at top?
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
You can use Master & Content page for this functionality.
Keep hyperlinks in MasterPage and add other 2 pages as content page.
|
|
|
|
|
You don't have to do anything special. Just create a page that contains frames, and put your page in one, and your static page in the other.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
thank you very much Christian...
could you give a sample link ....(you mean i need to create frames in html page and put target as .aspx page)??
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
www.diawebster.com[^]
That's my company site. The main page is just default.htm, I believe. It goes there automatically, but it's a HTML page. The top aspx uses javascript to control the bottom frame ( they are named for this purpose ). Any links in the bottom section just work, they all work within the frame they are in.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi
I have a repeater control and a textbox in itemtemplate of repeater control. Now I am creating multiple textbox dynamically and bind to the repeater . so i m getting multiple textbox in repeater at runtime.
I need to set the focus on pressing on space bar key on these textbox. actully my requirement is that every textbox accept only one word.
Pls suggest me.
Regards
Vikas
sdsds
|
|
|
|
|
You need to write some javascript to enforce both of these rules.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi
Please send any helpful link for these.
Please suggest me.
Regards
Vikas
sdsds
|
|
|
|