I have three ASPX Pages. The ASPX Page which get called from the two other Page is a Page where i can Upload files.
I call that Upload-Page from the other two Pages with JavaScript:
function UploadFax_Click() {
var grid = ISGetObject("WebGrid1");
var curSelObj = grid.GetSelectedObject(); // get selected object
var row = curSelObj.GetRowObject(); // get the WebGridRow object
if (row.Type == "Record") {
var s_id = row.KeyValue
}
window.location = '../Admin/UploadFax.aspx?suppid=' + s_id;
}
Then on the Upload-Page i get the QueryString:
If Not IsPostBack And Len(Request.QueryString("suppid")) > 0 Then
If Not Request.QueryString("suppid") Is Nothing Then
Session("suppid") = Request.QueryString("suppid")
End If
End If
What i need is that if i call the Upload-Page from one of the two Pages the functions of the Upload-Page should be restricted.
For Example: If i call the Upload-Page then Checkbox.Disabled = true and from the other page Checkbox should be enabled.
My idea was to send a second parameter from that page, then get the parameter with Request.QueryString and then use if/else to enable oder disable that checkbox.
Question is, is there another, better possibility to do that what i want? If yes how can i do that?
Using QueryString may cause a security violation , Why not you use Session parameter,
when you Call it from the First Page then set
Session("IsCalled")="1"
in the second page load check
IF Not Session("IsCalled") Is Nothing AndAlso Session("IsCalled")="1" Then
CheckBox1.Enabled=False
End If
and Vise Versa in the first page load.
You can check the Request.UrlReferrer and dance from it:
Dim restrictedAccess As Boolean = Not IsNothing(Request.UrlReferrer) AndAlso
Request.UrlReferrer.AbsolutePath.IndexOf("/Original.aspx", StringComparison.InvariantCultureIgnoreCase) >= 0
Checkbox.Disabled = Not restrictedAccess
Related
I want to implement a serverside download process which reports its progress to the client.
I defined a global variable in my .aspx site class:
Public progressStatus As Integer
Then a start a new Thread to download the images in a List, which also changes the value of the global variable:
For Each imageUrl In imageFiles
currentUrlCount = currentUrlCount + 1
indexOfUrlSplit = imageUrl.LastIndexOf("/")
localFilename = imageUrl.Substring(indexOfUrlSplit + 1)
If localFilename <> "" Then
httpClient.DownloadFile(url, localImage)
progressStatus = CInt((currentUrlCount / totalUrlCount) * 100)
End If
Next
I use the SetIntveral Javascript methods to check for the value of the global variable every 2 seconds:
var progStat;
setInterval(function() {
progStat = <%=progressStatus%>;
document.write(progStat + "\n");
}, 2000);
Through debugging I checked that the global Variable in the Code behind is calculated and changed correctly. Anyway, Javascript keeps the initial Value of 0.
I would be glad if someone could help me with that problem!
Thank you very much everybody,
Max
When you use syntax like that:
progStat = <%=progressStatus%>;
progressStatus value is retrieved once and converted to string when page is rendered. At that time value is 0. It isn't retrieved from server every time you call that script.
It means javascript function rendered on your page looks like:
progStat = 0;
When you keep calling that function multiple times client-side it does not change as page isn't re-rendered.
You need to make use of an Ajax call to retrieve the value from the server. Use the result from the call together with JQuery and then update the UI
I have an include file that contains the primary navigation menu for the site. I want to be able to set a CSS class for the current page. This is what I've been able to put together so far:
public function GetFileName()
Dim files, url, segments, current
'get then current url from the server variables
url = Request.ServerVariables("path_info")
segments = split(url,"/")
'read the last segment
url = segments(ubound(segments))
GetFileName = url
end function
if GetFileName = "index.asp" then
current = "current"
else
current = ""
end if
I'm thinking that a Select Case statement would be the thing to use in this scenario, I'm just not sure how to go about constructing it? Thanks in advance!
You'll need to add the definition of Iif to your code (from here: http://support.microsoft.com/kb/219271 )
Function IIf(i,j,k)
If i Then IIf = j Else IIf = k
End Function
I assume you have something like this.
<li>Click me to go somewhere</li>
You can do this:
<li>Click me to go somewhere</li>
You could do it in jquery
jQuery add class based on page URL
$(function() {
var loc = window.location.href;
if(/index.asp/.test(loc)) {
$(body).addClass('index');
}
});
I think that this is something very easy, but I cannot get this to work.
I have a form with a button "Delete". It calls www.mypage.com/adm/ads.asp?del=12.
So list.asp sees that there is a querystring with del=12 and deletes correspoding item.
After delete I want to refresh this page (something like Response.Redirect www.mypage.com/adm/ads.asp), so that querystring del=12 disappears.
I cannot get it working.
If (Request.QueryString("del").Count > 0) Then
id = Request.QueryString("del")
sql = "delete from Ads where ID = " & id & ""
on error resume next
conn.Execute sql
If err<>0 then
Response.Write("Delete error!")
Else
Response.Redirect http://www.mypage.com/adm/ads.asp
//Call opener.location.reload()
End if
The page is reloaded, but del doesn't disappear from query string.
The parameter to Response.Redirect should be a string - what you have is a syntax error:
Response.Redirect http://www.mypage.com/adm/ads.asp
Should be:
Response.Redirect "http://www.mypage.com/adm/ads.asp"
To make it generic and not mess with raw URLs you can have such code instead:
Response.Redirect(Request.ServerVariables("SCRIPT_NAME"))
The SCRIPT_NAME server variable will return the relative path of the currently executing script, no matter what the page is called and where it's located.
This the end of my code
...
If lblErrMsg.Text = "" Then
Response.Redirect("UserPage.aspx")
End If
I want to pass the value of txtUser(I create It in the current page...) to the UserPage.aspx.
Thank's for helping me ...
This is in VB.net not in c# Please
C# Version
1) Use querystring
Response.Redirect("user.aspx?val="+txtBox.Text);
and in userp.aspx.cs,
string strVal=Request.QueryString["val"];
2)Use Session
Setting session in first page before redirecting
Session["val]=txtBox.Text;
Response.Redirect("user.aspx");
and in user.aspx.cs
String strVal=(string) Session["val"];
EDIT :VB.NET VERSION
1) Use Querystring
Response.Redirect("user.aspx?val=" + txtBox.Text)
and in user.aspx.vb
Dim strVal As String = Request.QueryString("val")
2)Use Session
Setting Session in firstpage
Session("val")=txtBox.Text
Response.Redirect("user.aspx")
and in user.aspx.vb.
Dim strVal As String = DirectCast(Session("val"), String)
You can pass it in the query string, like this:
Response.Redirect("UserPage.aspx?user=" + HttpUtility.UrlEncode(txtUser.Text));
And then retrieve it via:
string user = Request.QueryString["user"];
If you're worried about users messing with a query string (be sure to validate it), you could also store a Session variable before doing the redirect.
warning: this is a gross but easy solution
Session("myTextbox")= txtUser.Text
this will persist the value so on the page_load of the next page you can say
txtUser.Text=Session("myTextBox")
What are you passing form page to page? Is it a list of things. You could have an object with different properties and could then pass it through a session. If you have multiple pages I would suggest doing this if you could end up reusing it else where. Passing it through the url, you would then need to validate it, because if someone types the url with the correct information or something that is being directly input into a database they could cause problems and/or unexpected results.
The current form is here. It is not complete, and only a couple options will work.
Select "Image CD" and then any resolution and click "Add to Order." The order will be recorded on the server-side, but on the client-side I need to reset the product drop-down to "{select}" so that the user will know that they need to select another product. This is consistant with the idea that the sub-selections disappear.
I don't know whether I should be using ASP postback or standard form submittal, and most of the fields need to be reset when the user adds an item to the order.
I'd use Response.Redirect(Request.RawUrl) method to reset the form data from the server side.
A little explanation: this is PRG design pattern
Used to help avoid certain duplicate
form submissions and allow user agents
to behave more intuitively with
bookmarks and the refresh button.
A workaround for this question:
necessary data may be stored in Session for example. This means we getting the data with the first POST, putting it to the storage, performing redirect and getting it back.
In the pageload event on the form, you need to add something simalar to this:
if (IsPostBack)
{
//Proccess the order here
ProductOption.SelectedIndex = 0;
}
That will allow you to process the order, but then start over the order form.
The simplest means would be a recursive function that forks on the type of control
private void ResetControls( Control control )
{
if ( control == null)
return;
var textbox = control As TextBox;
if ( textbox != null )
textbox.Text = string.Empty;
var dropdownlist = control as DropDownList;
if ( dropdownlist != null )
dropdownlist.SelectedIndex = 0; // or -1
...
foreach( var childControl in controlControls )
ResetControls( childControl );
}
You would this call this function in your Load event by passing this. (This is presuming you want to reset more than a single control or small list of controls).