|
Not trying to be a smart-ass, but why don't you just try it?
Place some dummy code in the finally block and see if it executes. (Use a break-point)
My hunch is that the finally code will execute. Also it may depend on which event the Response-Redirect is placed. (PageLoad, PageInit, ButtonClick, etc)
Post your results, so we all can learn.
|
|
|
|
|
I'm beyond mortified that I didn't think of that. Especially since after posting the question I ran the code to check something else, but putting a break point there just never occurred to me.
Ok, so thanks to David's suggestion I have an answer.
As it is written that code will throw an exception on the Response.Redirect with the following message:
Quote: {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.} However, it still does the redirect after going through the finally block.
Changing the Response.Redirect to
Response.Redirect("SomePage.aspx", false);
will save it from throwing the exception, but will still run the code in the finally and any code after it and then will do the Redirect.
Live and learn.
modified 11-Dec-12 9:26am.
|
|
|
|
|
As you've already figured out, code in the finally block is guaranteed to execute no matter what (unless the runtime host decides otherwise or a system error forcefully terminates the process itself)
|
|
|
|
|
Finally block will always execute, no matter if you redirect your page or throwing some exception.
Finally block will not execution on only Some Exceptions[^]
When you pass 2nd optional Boolean parameter, it indicate whether you would like to complete page execution or just want to redirect page and leave current execution.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
You already have your answer but to explain Response.Redirect a little more: It is telling the Response object to redirect the user to the new page. What happens is the client gets that message and then requests somePage.aspx. So, it roundtrips but your C# thread will finish. It's essentially just adding a property to the Response object.
Server.Transfer will still finish your C# thread (finally will still run) but the client will not roundtrip. Execution will stay on the server and go to somePage.aspx and execute it and send the Response object back to the client.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Very well put. Thanks ryanb31.
|
|
|
|
|
when i m trying to update image in sql database i m getting error as"Cannot bulk load. The file "System.Byte[]" does not exist."
my code is as follows.pls help.
protected void Button1_Click(object sender, EventArgs e)
{
{
if (FileUpload1.HasFile)
{
byte[] productImage = FileUpload1.FileBytes;
string constr = "Server=AOD257; Database=Edusocial;User ID=sa; Password=password";
string query = "UPDATE Profile SET [Pic] = (SELECT Pic.* from Openrowset(Bulk '" + productImage + "', Single_Blob) MyImage) where Id =11651658";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@Pic", SqlDbType.Image).Value = productImage;
con.Open();
int result = com.ExecuteNonQuery();
con.Close();
if (result > 0)
{
Response.Redirect("Default.aspx");
}
}
else
{
lblmessage.Text = "Please Select Image File";
lblmessage.Visible = true;
}
}
}
|
|
|
|
|
I can't see how that would work, mixing unicode with bytes to enter into a blob.
"UPDATE Profile SET [Pic] = (SELECT Pic.* from Openrowset(Bulk '" + productImage + "', Single_Blob) MyImage) where Id =11651658";
versus
"UPDATE Profile SET [Pic] = productImage WHERE Id =11651658";
in which the latter is pure bytes from the file upload.
|
|
|
|
|
"UPDATE Profile SET [Pic] = '"+productImage+"' WHERE Id =11651658"
this query is working fine.but then image in image box is broked.its not been displayed.pls help.
|
|
|
|
|
You're nearly there:
"UPDATE Profile SET [Pic] = @Pic WHERE Id = 11651658"
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
So I separated some write functions, that update a XML file into separate classes, that generate a thread in the background to open, update and write the XML file using streamreader and streamwriter.
So I'm new to threads on vb managed code, and just found that StreamReader is not thread safe. I did some research and one MSDN article says I need to wrap the streamreader in textreader and synchronize.
I did some more research, stumbled across monitor.enter and monitor exit, and the singleton class, so that only 1 instance of the class can run at a time.
So I have a file called "Landing.xml" and I'm interested in only have 1 instance of the class work the file at a time.
Just looking for suggestions, or help with implementing. Will post code is someone asks.
|
|
|
|
|
Well I tried using monitor and so far so good. So I have like 15 of these class files that handle 1 xml file each, and they seem to be queuing up correctly, and waiting politely for the previous instance of itself to complete before firing again.
So the Yandex and Baidu bots have visited, and the updates were handled without error this time over the last 3 hour test period.
Well time will tell, will check the results again in the morning.
Still interested in the Singleton concept. Not quite sure how to implement it in vb
|
|
|
|
|
i want to retrieve images from a database and display them in a tiled view(at least three on a row) but i don't know how to go about that could someone please shed light on this for me?
|
|
|
|
|
Use an HTTP Handler.
Help people,so poeple can help you.
|
|
|
|
|
Hi all!
I have established a linq connexion with my database with this code behind.
And with manually set paging for 10 records.
data is shown in ListView.
How do I get the header sorting I'm using a linkbutton. Also I want to be able to insert a dropdownlist in the header. How do I receive this functionality.
With thanks in advance.
private void DisplayData(int startRow)
{
using (Origo.Vefur.Linq.dbMainDataContext db = new Linq.dbMainDataContext(Origo.WMMain.Helpers.Global.ConnectionString))
{
var empList = from el in db.owm_USERs
where el.showOnWeb == 1
select el;
ListView1.DataSource = empList.Skip(startRow).Take(10);
ListView1.DataBind();
}
}
My list view looks now like this
<asp:ListView ID="ListView1" runat="server"
onselectedindexchanged="ListView1_SelectedIndexChanged1"
onsorted="ListView1_Sorted" onsorting="ListView1_Sorting">
<LayoutTemplate>
<table id="Table1" runat="server" class="TableCSS">
<tr id="Tr1" runat="server" class="table-header">
<th align="left"><asp:LinkButton ID="lnkID" CommandArgument="id" CommandName="Sort" Text="id" runat="server" /></th>
<th align="left"><asp:LinkButton ID="lnkName" runat="server">Nafn</asp:LinkButton></th>
<th align="left">
<asp:dropdownlist runat="server" id="ddlWrokplace"
DataTextField="workplace" DataValueField='<%# Eval("workplace") %>' SelectedValue='<%# Eval("workplace") %>'></asp:dropdownlist>
</th>
But neither the sorting links nor the dropdown list are working properly
|
|
|
|
|
|
Is there a way to change or specify how virtual paths are resolved?
I'm creating a site on my machine, but for purposes of demonstration, I want to deploy it to a sub folder of an existing web site. So, on the web host, I have
wwwroot (which is the parent site)
wwwroot/demosite (which is the demo web site)
Of course, this means that a virtual path of "~/demosite.master" ain't gonna work, because that would resolve to "/demosite.master" instead of the desired "/demosite/demosite.master".
I tried using inline code, but of course that isn't allowed (some far-sighted MSoftie probably knew I was going to need to do this, and this is some sort of weird personal vendetta to prevent me from actually getting anything done).
What I want to do is to make the code change the various virtual paths used throughout the demosite, so that I don't have to remember to do it when I deploy to it's actual production server.
So, for localhost (when developing) and deployment onto the actual production server, I want to use the current virtual path, but for the demo version, I need to change the virtual path root.
Is that possible, and if so, how?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
When you deploy the site, you need to make sure that the "demosite" folder is an application. In IIS Manager, right-click on the folder and select "Convert to Application". Your app-relative paths (~/demosite.master ) will then resolve to the correct path.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm not sure I can change that, since the deployment is to a web host.
I was actually hoping for a web.config approach, or some other technique.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I am not sure if this trick may work for you, but you can create one section in configuration file indicating if you are running site for production or for testing.
if you config section says isTestMode="true" it means for testing otherwise production.
you need to add condition on every location that may be for one time. hope this may help you.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
Hi All,
I am trying to update a database table using entity framework, but some how I dont know why, but entity framework is updating the other column of the table which I am not setting up in my code. In my update statement after else statement, I am calling to update only column docid (rq.doc_id = doc_id) but I dont know why it is updating even the request_status column also. It is updating with 4 spaces and updating thats all.
I am actually not resetting the request_status value. It is very strange for me.
Can any body please help me in resolving this and getting rid of this problem.
I have my code as below
Using _databasefactory As New DatabaseFactory()
Dim context = _databasefactory.DatabaseContext
If Not String.IsNullOrEmpty(temp_doc_id) AndAlso Not String.IsNullOrEmpty(doc_id) Then
Dim reqs = (From r In context.requests Where r.claim.claim_no.Equals(claim_no) AndAlso r.temp_doc_id.Equals(r.temp_doc_id)) 'r.empl_accnt_no.Equals(emplacctnumber) AndAlso _
Dim res = 0
If reqs Is Nothing Then
Dim rq = New request()
rq.claim = (From r In context.claims Where r.claim_no.Equals(claim_no)).FirstOrDefault()
rq.empl_accnt_no = emplacctnumber
rq.manual_claim_no = ManualClaimNo
rq.doc_id = doc_id
rq.temp_doc_id = temp_doc_id
rq.request_status = "OANEW"
rq.last_update_ts = DateTime.Now
rq.create_ts = DateTime.Now
rq.comments = String.Empty
context.AddTorequests(rq)
Return context.SaveChanges()
ElseIf reqs.Count() <= 0 Then
Dim rq = New request()
rq.claim = (From r In context.claims Where r.claim_no.Equals(claim_no)).FirstOrDefault()
rq.empl_accnt_no = emplacctnumber
rq.manual_claim_no = ManualClaimNo
rq.doc_id = doc_id
rq.temp_doc_id = temp_doc_id
rq.request_status = "OANEW"
rq.last_update_ts = DateTime.Now
rq.create_ts = DateTime.Now
rq.comments = String.Empty
context.AddTorequests(rq)
Return context.SaveChanges()
Else
Dim rq = reqs.FirstOrDefault()
'If Not rq.claimReference.IsLoaded Then
' rq.claimReference.Load()
'End If
rq.doc_id = doc_id
res = context.SaveChanges()
Return res
End If
End If
End Using
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
I have problem with Composite Control in ASP.NET. Im making a classlibrary with this content \/ , but the problem is, that i cannot see it in toolbox, but i register it in web.config file, compile it and add a reference to it. And another problem is that my composite control cannot raise an event.
<pre>
namespace MyCompControl
{
public class CreateArticleEventArgs : EventArgs
{
public bool IsValid { get; private set; }
public Article article { get; private set; }
public CreateArticleEventArgs(bool IsValid, Article article)
{
this.IsValid = IsValid;
this.article = article;
}
public CreateArticleEventArgs(bool IsValid)
{
this.IsValid = IsValid;
this.article = null;
}
}
[
AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultEvent("Submit"),
DefaultProperty("ButtonText"),
ToolboxData("<{0}:CreateArticle runat=\"server\"> </{0}:CreateArticle>"),
]
public class CreateArticleControl : Control, INamingContainer
{
private Label labelHeader;
private Label labelIntro;
private Label labelImage;
private Label labelImageText;
private Label labelText;
private Label labelFileUploadStatus;
private TextBox textBoxHeader;
private TextBox textBoxIntro;
private TextBox textBoxText;
private TextBox textBoxImageText;
private FileUpload fileUpload;
private Button buttonCreateArticle;
private static readonly object EventCreateArticleKey = new object();
#region Create Article Event Delegate
[
Category("Action"),
Description("Raised when the user clicks the button.")
]
public event EventHandler CreateArticle
{
add
{
Events.AddHandler(EventCreateArticleKey, value);
}
remove
{
Events.RemoveHandler(EventCreateArticleKey, value);
}
}
#endregion
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
HttpContext.Current.Trace.Warn("OnLoad");
if (!Page.IsPostBack)
{
EnsureChildControls();
}
}
protected override void CreateChildControls()
{
HttpContext.Current.Trace.Warn("CreateChildControls");
labelHeader = new Label();
labelHeader.Text = "Header:";
Controls.Add(labelHeader);
textBoxHeader = new TextBox();
Controls.Add(textBoxHeader);
labelIntro = new Label();
labelIntro.Text = "Intro:";
Controls.Add(labelIntro);
textBoxIntro = new TextBox();
Controls.Add(textBoxIntro);
labelText = new Label();
labelText.Text = "Text:";
Controls.Add(labelText);
textBoxText = new TextBox();
Controls.Add(textBoxText);
labelImage = new Label();
labelImage.Text = "Image Upload:";
Controls.Add(labelImage);
fileUpload = new FileUpload();
Controls.Add(fileUpload);
labelFileUploadStatus = new Label();
labelFileUploadStatus.Text = "";
Controls.Add(labelFileUploadStatus);
labelImageText = new Label();
labelImageText.Text = "Image Subscription:";
Controls.Add(labelImageText);
textBoxImageText = new TextBox();
Controls.Add(textBoxImageText);
buttonCreateArticle = new Button();
buttonCreateArticle.ID = "buttonInsertArticleID";
buttonCreateArticle.Text = "Insert Article";
buttonCreateArticle.Click += new EventHandler(buttonCreateArticle_Click);
}
protected override void Render(HtmlTextWriter writer)
{
labelHeader.RenderControl(writer);
textBoxHeader.RenderControl(writer);
labelIntro.RenderControl(writer);
textBoxIntro.RenderControl(writer);
labelText.RenderControl(writer);
textBoxText.RenderControl(writer);
labelImage.RenderControl(writer);
fileUpload.RenderControl(writer);
labelFileUploadStatus.RenderControl(writer);
labelImageText.RenderControl(writer);
textBoxImageText.RenderControl(writer);
buttonCreateArticle.RenderControl(writer);
}
protected virtual void OnCreateArticle(CreateArticleEventArgs e)
{
EventHandler SubmitHandler = (EventHandler)Events[EventCreateArticleKey];
if (SubmitHandler != null)
{
SubmitHandler(this, e);
}
}
void buttonCreateArticle_Click(object source, EventArgs e)
{
string filepath = "";
if (fileUpload.HasFile)
{
filepath = HttpContext.Current.Server.MapPath("~/pictures/") + fileUpload.FileName;
fileUpload.SaveAs(filepath);
}
OnCreateArticle(
new CreateArticleEventArgs(true, new Article()
{
Author = HttpContext.Current.User.Identity.Name,
CreationDate = DateTime.Now,
Header = textBoxHeader.Text,
Intro = textBoxIntro.Text,
Image = filepath,
ImageText = textBoxImageText.Text
}));
}
}
}
<add tagPrefix="mycc" assembly="MyCompControl" namespace="MyCompControl" />
<mycc:CreateArticleControl ID="cac" runat="server" oncreatearticle="cac_CreateArticle">
</mycc:CreateArticleControl>
protected void cac_CreateArticle(object sender, EventArgs e)
{
throw new NotImplementedException();
}
<>
A would be glad for any advice...
|
|
|
|
|
Actually i'm using color extender to pick the color in asp.net...but while i'm picking the color it generate the hex decimal values....but i need only rgb values...Pls any one guide me....
|
|
|
|
|
This has already been answered in the C# forum. Please do not post the same question in more than one place.
One of these days I'm going to think of a really clever signature.
|
|
|
|