I am using a asp:HyperLink as it gave me the ability to open up the linked page in a new tab.
One issue I am facing with this control is that as the info I need to pass is confidential, I do not want to do something like:
<asp:HyperLink ID="LinkButton2" runat="server" Target="_blank" NavigateUrl= '<%# String.Format("SPage.aspx?val={0}", Eval("Uid")) %>'>View/Print</asp:HyperLink>
In other words, I do not want to pass info such that it is viewable by the user. Is there any other way around this. Is there any other control that can easily open up the link on another page and yet give me the ability to pass info without querystring (as this will be viewable). My main concern is that I am passing CONFIDENTIAL info in the querystring and as such do not want to user to view it.
What you can do :
From the server side :
LinkButton2.NavigateUrl="~/SPage.aspx?uid=" +Uri.EscapeDataString(Utils.Encrypt(Uid)); //Utils.encrypt is your encryption function
Users will see it , but they won't understand nothing from it.
Later , on your page :
var myValue = Utils.Descrypt(Uri.UnescapeDataString(request["uid"]));
Related
I have an ASP.NET webforms application and a requirement to add a form to a page which will be posted to an external URL, a payment processing provider. The form needs to include specific hidden inputs, one of which is a hashed string representation of the form data.
I understand given limitations of webforms I can't nest a second form within the main <form runat="server" />. However, I don't have the option to locate my form outside of that main form (due to the CMS this site is built into).
I know I can use an ASP.NET Button control with a PostBackUrl attribute which allows the form to post to a specific URL. However, this posts every form element on the page, including __VIEWSTATE, __EVENTTARGET etc.
This is not desired behaviour. I only want to submit specific data. Also, this makes it difficult (impossible?) to generate the hash representation of the form because this would have to include viewstate etc.
I also don't have the option to post the data from the code behind because the client is expected to continue their interaction at the target URL.
Do I have any options here? This must be possible, but an internet search has returned very little.
UPDATE: I'm looking for a solution that doesn't rely on Javascript.
One option would be to utilize ajax. Simply use it to post data you need and you don't even have to redirect or anything. You'd be in control of literally everything (well as long as the user has javascript turned on, of course).
You can use ajax update panel for this .
put asp:scriptManager on page
<asp:scriptManager></asp:scriptManager>
<asp:updatePanel runat="server">
<contentTemplate>
your controls to be submitted to next page
<asp:button><asp:button>
</contentTemplate>
</asp:updatePanel>
and put other controls outside updatePanel.
I am slowly, piece by piece learning what I am doing with ASP.NET
I've created the beginnings of my new web application, but I am often coming up against the issue that ASP.NET renames elements IDs or in the case of form fields, their names.
I have a form which is basically a sales system. It is essentially made up of two User Controls, one is a form for Customer Details (name, address etc) and the second is a form for the customer's purchases, it consists of a number lines dynamically created by Javascript created as you list the items the customer is purchasing.
Both these sections are User Controls because they are to be used for other areas of the system where this data will need to be recalled/re-entered.
When the USer Control is loaded, the field which contains the Customers' Name is renamed "m$mainContent$customerForm$name" I understand where this comes from, "m" is the ID of my Master Page, "mainContent" is the main Content Placeholder and "customerForm" is the name of the User Control.
In fact, in my case, this will always remain the same on all forms, so it is relative easy to overcome... but... suppose it wasn't
I can see there are ways I could deal with this with Javascript, but the form doesn't need an AJAX submit, a normal Post will do fine for this, so when I open up the recieving page I want to call Request.Form("name")% to save the customer's name into the database, but of course I really need Request.Form("m$mainContent$customerForm$name")%
How would I dynamically extract those prefixes from the posting form to ensure that if I rename anything or use it in a different scenario, the problem will not break it?
I am using .NET 2.0, so can't use Static Client.
This is really old but let's see if it's useful for you.
Getting this example I managed to get the value from a given field name without prefix.
I'm sure it is not the best solution, but it was useful for me. Let's say you want to recover the value of a field named "hfIdAviso", that comes in the POST as "ctl00$body$hfIdAviso":
var value = Request.Form.Cast<string>()
.Where(key => key.EndsWith("hfIdAviso"))
.ToDictionary(key => key, key => Request.Form[key])
.Values.FirstOrDefault();
That will return the value for that field.
Hope it helps.
If you include runat="server" in the declaration of your user control in the ASPX page, then you can access this control by just using the ID value of the control.
For example
In the ASPX:
<uc:MyUserControl ID="mycontrol1" runat="server" />
In the code behind (in C# syntax):
object foobar = mycontrol1.SelectedValue;
suppose you have a form inside user control that has a TextBox field with ID="txtfname".You have registered your user control in page1 and you want to POST form data to page2 :
in page1 you have user control:
<My:WebUserControl1 ID="myuc" runat="server" />
in page2 codebehind , you can get the value of user control form field (txtfname) this way :
string firstName = Request.Form["myuc$txtfname"];
I found a workaround for my specific need, but I thought I'd ask this question anyway.
Say I have a typical data entry web project with a master page -- instead of using the Session variable and using Response.Redirect or Server.Transfer to redirect users who are part of the way through data entry to the next step, I'd rather use cross-page posting.
I tried setting up one of my websites in this manner, with a button like:
<asp:Button ID="next" text="next" runat="server" PostBackUrl="EnterInfo.aspx" />
When I went to test the changes, my <form> tag hadn't changed at all:
<form id="aspnetForm" action="SelectUser.aspx" method="post" name="aspnetForm">
Did I miss any details here, or is cross-page posting simply not intended for use with a master page?
Edit:
The form tag above is the tag as rendered on the client -- not the server-side tag. I've read MSDN articles (like this one) that seem to me to explicitly state that cross page posting actually posts the form to another page.
Perhaps I've misinterpreted this as changing the form's action, but regardless my source form does not post invoke anything anywhere on my target when I click the button I altered -- it merely posts back to the current page.
I don't think using the PostBackUrl attribute will change the action of the form in the markup, as there could be many other controls just doing a normal postback. I imagine that some javascript is used to change the action of the form when this particular button is pressed.
You need to place a declaration on the second page where data come from.
So you have:
PostBackUrl="EnterInfo.aspx"
On EnterInfo.aspx you declare where you can get informations
<%# PreviousPageType VirtualPath="~/SelectedUser.aspx" %>
and you get them by...
if (Page.PreviousPage != null)
{
if(Page.PreviousPage.IsCrossPagePostBack == true)
{
GetTheClass = PreviousPage.MyDataClass;
}
}
The PostBackUrl not change the form url.
Some reference.
ASP.NET how to access public properties?
Cross-page postbacks and back again retaining data from source page
Ps
At first I was thinking that you have just type what you see at render, but if not the case As #Mystere point out you need to run this inside an asp.net form.
First, as Graham says.. PostBackUrl does not change the postback action. Second, you can only use PostBackUrl on an asp.net enabled form, which means the form must have runat="server"
I have a User control (because I use the same in other page, so I thought I should reuse code and not double my work), but in this page I show a list of companies and each one has a company number, I need to pass this company number to that User Control and it has to reload using that passed company number.
How can I accomplish this?
what I have so far:
alt text http://www.balexandre.com/temp/2009-09-17_0917.png
the Show company structure link is made of
<a href="javascript:showStruct('112:201334607','5564967221');"
class="showStructLink">Show company structure</a>
the showStruct method is written like
function showStruct(pid, cnr) {
if (_showStrut == 0)
return;
// fancy stuff to be more apealing visually
$("#tdSearch").removeClass("tabTitleUp01").addClass("tabTitleDownUp01");
$("#tdStruct").removeClass("tabTitleDownUp02").addClass("tabTitleUp02");
$("#srtr1").hide();
$("#srtr2").hide();
$("#sttr1").show();
// enable Search Results tab to be clicked in order to get back
$("#tdSearch")
.addClass("pointer")
.bind("click", function() { hideStructure(); });
// pass the company number and reload wcCompanyStruture web user control
// __doPostBack('RefreshWebUserControl', cnr);
}
I can make a simple aspx page with the control inside and from jQuery invoke $.get() to run and populate the control correctly, but I really want to learn how to do this properly, using the ASP.NET AJAX Method to send a number and call RefreshData on it
using code-behind it is easy to refresh the user control, just invoking
wcCompanyStruture.RefreshData("companyNumberHere");
what do I need to do in my User Control side and well in the showStruct method to create this behavior?
All help is appreciated, Thank you.
I know this is not the answer to you question but I think you may be asking the wrong question.
It looks to me as if you have a search result+details view scenario that you are going about the wrong way.
When you click "Show Company structure" you want to see the details on the second tab right? If this is the case then the tab approach would be confusing to the user, it would be better with a modal popup that shows the details. No postback just AJAX load a page with the details into a modal popup window.
This is very easy with JQuery using the dialog widget in JQueryUI and the AJAX load function $('#SomeDiv').load('details.aspx?id='+companyid);
http://docs.jquery.com/Ajax/load#urldatacallback
It would give a much better user experience and it is surprisingly simple to code.
I hope this helps.
You can use a LinkButton for each "Show Company Structure" link, and set the CommandArgument property with the corresponding company id. The LinkButton will cause a postback.
A second solution would be to use a hidden variable : <input type="hidden" id="hiddenCompanyNumber"> and set it's value in the showStruct method. You can then call __doPostBack(), for which you need a control upon which to postback I think.
All in all, I think the first solution is less hacky.
You can find it here
http://codeclimber.net.nz/archive/2007/06/26/how-to-refresh-an-updatepanel-from-javascript.aspx
don't worry about the article title it has what you need Just do the four steps and you are ready to go.
I have in my webform many TBs bound to a property in the code behind:
<asp:TextBox ID="tbFirstName" Text="<%# Contact.FirstName %>" runat="server" />
<script language="c#">
public Contact Contact
{
get
{
return (Contact)ViewState["Contact"];
}
}
</script>
<script language="VB">
Public ReadOnly Property Contact() As Contact
Get
return ViewState("Contact");
End Get
End Property
</script>
While Contact is that property.
I want that when the user inserts text, it should immediately be bound to the Contact object e.g. when the user presses a key down or even when losing focus (TextChanged) would be good too.
Is there a way to do it dynamically (rather than manually retrieve the data from all the TBs and update the Contact object)?
I am actually willing to achieve two-way databinding with simple textboxes spread in the form body.
Note: I am not going to store the items to the DB of course, I just want the object (Contact) which resides in the state manager.
Do you realize you're talking about a web application? It's running in the users' browser. In order to update a database, you have to make a round trip to the server, either through AJAX or through a postback. Do you really want to do this for every keystroke?
From your comments, it's apparent that you aren't trying to write back to the database on every keystroke.
Still, data binding doesn't work this way. Data binding is a purely server-side action in ASP.NET. Even the two-way data binding afforded by the Bind method only works on a full postback (though I admit I haven't tried it with an UpdatePanel).
As an experiment, create a new page, and set up two-way databinding (see "Using the FormView for a More Flexible Data Modification User Interface" in An Overview of Inserting, Updating, and Deleting Data for an example). Once you get it working "normally", try putting the FormView into an UpdatePanel and see if the Bind still works. If so, see if you can get the UpdatePanel to fire on every keystroke.
Stop thinking like you are developing a desktop application! Because yo are not. The "Contact" object lives on the server while your textbox "lives" at the client, refreshing the server object would be very costly, you'll have to do async transfers between the server and the client with the new data, and doing it at so shorts intervals wouldn't even be possible. Thought you can add a delay on the textbox after which you would transfer the data to the server. Why would you ever need this?