Thứ Tư, 14 tháng 3, 2012

Passing values from Javascript to ASPX

Hi,
Based on your description, you want to retrieve the variable from JavaScript in aspx page.
I'm agreed with mcguzic. You can set the variable from JavaScript into Hidden control and then you can get it in aspx page.
HTML: 
<script type="text/javascript">
function abc() { 
  var str="value"; 
  document.getElementById("Hidden1").value=str; } 

script> <body> 
    <form id="form1" runat="server">

    <div> 
        <input id="Hidden1" type="hidden" runat="server" />

        <asp:Button ID="Button1" runat="server" OnClientClick="abc()"
 Text="Button" onclick="Button1_Click" />

    div> 
    form> body>
 Code Behind:
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write(Hidden1.Value);
    }
 But you should pay attention on the order of setting the variable to Hidden control in JavaScript and retrieving the value of Hidden control in aspx page. In the same event handle, it needs execute the Client first. For example,  OnClientClick="abc()" will be executed before onclick="Button1_Click". Otherwise, you will get the empty.
Hope it helps.

Boat Anchor

Boat Anchor là những mã nguồn hoặc thành phần phần mềm hoặc phần cứng không phục vụ vào  mục đích hữu ích nào của dự án hiện tại. Boat Anchor  thường bị tốn kém, do ban đầu dự án có nhu cầu cần mua hoặc sử dụng các mô đun phần mềm hoặc thiết bị phần cứng nhưng cuối cùng không dùng đến.
Description: http://sourcemaking.com/files/sm/images/anchor.jpg

Hậu quả cho người quản lý và lập trình viên đầu tư công sức đáng kể để làm sao cho sản phẩm hoàn thiện. Tuy nhiên, sau sự đầu tư đáng kế thời gian và nguồn lực, mọi người nhận ra rằng sản phẩm vô dụng, chấp nhận bỏ sang một bên và tìm giải pháp kỹ thuật khác để thay thế.

Giải pháp tái cấu trúc


Thực tế cho thấy, khi nghiên cứu triển khai dự án cần đưa ra giải pháp kỹ thuật thay thế(dự phòng), một phương án dự phòng cần được thiết lập để giảm thiểu việc phải làm lại dự án. Việc lựa chọn giải pháp kỹ thuật dự phòng là chiến lược giảm thiểu rủi ro quan trọng.
Giải pháp kỹ thuật dự phòng nên được xác định cho tất cả các công nghệ nền tảng(công nghệ mà hầu hết các phần mềm phụ thuộc/sử dụng công nghệ này) và các công nghệ có phạm vi nguy cơ cao. Giải pháp kỹ thuật dự phòng nên được đánh giá cùng với đường găng cộng nghệ trong quá trình lựa chọn giải pháp.

Thứ Ba, 13 tháng 3, 2012

Server.Transfer Vs. Response.Redirect

If you read a lot of industry magazines and ASP.NET code samples, you may find that, although the majority use Response.Redirect to send the user to another page, some seem to prefer the rather mysterious-sounding Server.Transfer. So, what's the difference?
Well, Response.Redirect simply sends a message down to the browser, telling it to move to another page. So, you may run code like:
Response.Redirect("WebForm2.aspx")
or

to send the user to another page.Response.Redirect("http://www.karlmoore.com/")
Server.Transfer is similar in that it sends the user to another page with a statement such asServer.Transfer("WebForm2.aspx"). However, the statement has a number of distinct advantages and disadvantages.
Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.
But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that.
Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.
That's not all: The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.
For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").
This technique is great for wizard-style input forms split over multiple pages. But there's another thing you'll want to watch out for when using the preserveForm parameter. ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer the form and query string values. You'll find this documented at http://support.microsoft.com/default.aspx?id=kb;en-us;Q316920.
The unofficial solution is to set the enableViewStateMac property to True on the page you'll be transferring to, then set it back to False. This records that you want a definitive False value for this property and resolves the bug.
So, in brief: Response.Redirect simply tells the browser to visit another page. Server.Transfer helps reduce server requests, keeps the URL the same and, with a little bug-bashing, allows you to transfer the query string and form variables.
Top Tip: Don't confuse Server.Transfer with Server.Execute, which executes the page and returns the results. It was useful in the past, but, with ASP.NET, it's been replaced with fresher methods of development. Ignore it.