I have an ASP page with a table containing always different rows, dynamically loaded from a MSSQL DB. In each row of the table I have created a Button, called Details, that is dynamically created during the writing of the table. This Details button is added with the following code:
Button detailsButton = new Button();
detailsButton.Height = new Unit("18px");
detailsButton.Width = new Unit("65px");
detailsButton.Text = "Details";
detailsButton.ID = row.ItemArray[0].ToString();
detailsButton.PostBackUrl = "~\\DetailsPage.aspx?selectedSignalling=" + detailsButton.ID;
//detailsButton.Click += detailsAgencyButton_Click;
//detailsButton.OnClientClick = "return true;";
table1cell4.Controls.Add(detailsButton);
table1row.Cells.Add(table1cell4);
The intention is to redirect the client towards the Postback URL when one button is pressed on a row. The Postback URL is dynamically created for each button, associating to each of them the ID of the item that the user would choose to display the details.
While this works fine on the my development environment, that is running IIS 7.5, this is not always working on the production environment, that runs IIS 6.0 and that cannot be updated. On IIS 6.0, some clients does not notice any problem, while others are not able to display the details page, but, when clicking on the Details button, the postback URL is not loaded and instead there is only the reload of the current page.
I have tried to change many settings (set the detailsButton.Click, set the OnClientClick to "return true;"), but without luck. I have only noticed that adding the:
detailsButton.OnClientClick = "return true;";
instruction, the redirect does not work in IIS 7.5 too. So it seems to me that when OnClientClick returns something (true/false), the PostBack is not activated, while some of the clients probably does not return any OnClientClick and the PostBack is activated.
I solved my problem using javascript redirect associated to onClientClick event and returning false on the same event. This prevents the server to be invoked and the client redirects towards the new page without refreshing the old page.
detailsButton.OnClientClick = "windows.open(' new_page.aspx ', '_self'); return false;";
Related
I am facing automatic multiple clicks on my Button in all pages of my website. I put JavaScript to disable the button on click. It's working but on the server side it's not working. I want to stop double click on server side without JavaScript.
There is nothing to be easily done without JavaScript included. But let's assume there is no way to use JavaScript for a reason.
You will need to trace the server side calls, for example:
You can have a seconds life time variable (session variable) and each time you call the server you set it to true, and if you found it true on the next call this means it is a second click.
Try adding the following code to the button
btnSubmit.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnSubmit, null) + ";");
Please let me know if this solved your problem
In your click event you can just add in
Btnsubmit.enabled=false
I have an application with a bunch of wizards. In one of the wizards when the user is on the last step some code runs in the code-behind to check the form's values so far. If there is an issue with one of the values, a yes/no pop-up gets displayed (user control). If the user clicks on yes, they get taken to the step with the incorrect values via changing ActiveStepIndex in the code-behind.
This works locally and on my build server, the step gets changed, navigation happens and all is well. But on my QA server another post-back is triggered immediately afterwards that navigates to the previous step again.
Through debugging I have found that the AJAX post-back is triggered from the _domReady function of MicrosoftAjax.js. Apparently it's supposed to check for browser navigation events or some such. In my case the state comparison that gets done in the _navigate function results in the second post-back happening because the two states are different. The new state is different from the old state, which gets set by the ScriptManager source.
function Sys$_Application$_navigate(entry) {
this._ensureHistory();
var state = this._deserializeState(entry);
if (this._uniqueId) {
var oldServerEntry = this._state.__s || '';
var newServerEntry = state.__s || '';
if (newServerEntry !== oldServerEntry) {
this._updateHiddenField(newServerEntry);
__doPostBack(this._uniqueId, newServerEntry);
this._state = state;
return;
}
}
this._setState(entry);
this._state = state;
this._raiseNavigate();
}
Any idea why the server states might be different in one environment but not the other? It happens in all browsers, by the way.
I turned out the warning pop-up was outside the wizard's update panel. After I moved it inside the update panel, the view states were in sync and no extra post-back was made.
I still don't understand why it worked fine locally, though.
I have a local version and version that is hosted by IIS onto a server.
When i click the link to load up my page all the styling is fine and it suppost to be where it is:
I choose all my data and submit my page which runs this C# code.
newRecord.NumberofItems = Convert.ToInt32(totalitems);
cPostFunctions test = new cPostFunctions();
test.InsertNewRecord(newRecord);
//Add Message
Response.Write("<script langauge=\"javascript\">alert(\"Entry Submitted\");</script>");
Page_EntrySubmitted(null, EventArgs.Empty);
In the Page_EntrySubmitted method all it does is set the Textboxes, Dropdowns and labels to NULL.
When the page refreshes after the alert this happens:
All my styles are getting pulled through but it seems as it is stretching everything.
THIS ONLY HAPPENS ON THE SERVER NOT MY LOCAL VERSION
Guys I am trying to pass a variable from one page to another. Upon searching I found that either QueryString method is used or Session is used for passing variable. I don't like QueryString method as it displays data in URL which could be modified so I went for sessions.
Now I have added a DataGridView in asp which has a button in each row. Upon clicking this button, a session variable is created having the value of 1st column of the row in which the button was clicked and then it redirects to another page in which I am using this session variable.
Now the problem is, when I was using the Visual Studio debugger, this was working fine and the variable value kept changing according to the button click. But once I uploaded the site to hosting, the variable is created the first time I click the button in DataGridView but when I press the button again in different row, the variable value doesn't change. It remains constant, unless I press F5 in browser on the redirected page, only then the value gets updated.
I think the value gets stored in browser's cache and doesn't change until I force refresh the page. What should I do to solve this problem? is there any other way to pass variable other than the above two mentioned methods?
Code for creating session and redirecting :
GridDataItem item = (GridDataItem)e.Item;
string ticketid = item["ID"].Text;
Session["viewID"] = ticketid;
Response.Redirect("View.aspx");
Code for retrieving session :
String s = Session["viewID"] as String;
I would also like to avoid using cookies, many users have cookies disabled in their browsers so using cookies wont be optimal.
Try this on button click event to store in cookie
Response.Cookies["viewID"].Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(ticketid));
and you can get value using this code:
Try this:-----
String s =Encoding.UTF8.GetString(Convert.FromBase64String(Request.Cookies["viewID"].Value));
Sorry I forget .Value after Request.cookies["viewID"]
It was just saving the value in cache. I have to force turnoff the cache settings in ASP web application. Problem solved.
I encouter some postback issue when using GetPostBackEventReference. Here is the Scenario:
I have a javascript modal popup dialog and got a button in this modal dialog which used to select things (this is NOT an asp:button control)
When this javascript dialog HTML button is clicked, it will call the MS AJAX web service call by the javascript: eval() method. And this MS AJAX web service call is dynamically generated. So the code is like this:
var serviceCall = svcCall + "(" + parameters + ")"; //dynamically generate the MS AJAX web service call here
eval(serviceCall);
//use eval to trigger the MS AJAX web service call
As you may all know, after complete the MS AJAX web service, you can define a callback function to handle the completion:
function OnComplete(result, userContext, methodName) {
//force to call postback manually
eval($(userContext[0]).val());
//close the javascript dialog here
}
As I have mentioned before, the MS AJAX web service call is built dynamically, and when the MS AJAX web service call is construct, it will be passing a userContext which contain the postback value (i.e. "__doPostBack('ctl00$ContentPlaceHolder1$btnSelectUser','')", so when the javascript eval() is called, it simulate a asp:button click postback.
The userContext[0] basically holding a asp:hidden field's ClientID, and the hidden field's value is set during the Page_Load event:
protected void Page_Load(object sender, EventArgs e)
{
btnSelectUser.ValidationGroup = "popupSelect";
btnSelectUser.CausesValidation = false;
this.hdnBtnPostback.Value = Page.ClientScript.GetPostBackEventReference(btnSelectUser, string.Empty, false);
}
As you can see, this is how I bound the asp:button (i.e. btnSelectUser) 's Click Event to the asp:hiddenfield using the GetPostBackEventReference, and set the registerForEventValidation argument to false. I have also tried to use different ValidationGroup and set the CausesValidation to false, but no hope. :(
In summarize, I bound the asp:button's Click PostBackEventReference(i.e. __doPostback(....)) to the asp:hidden field's Value attribute, and using javascript eval() to eval this hidden field's value in order to manually trigger postback.
p.s. the btnSelectUser is an asp:button control and used to call out the javascript modal dialog.
Ok, here is the Problem:
In the same page, there is some asp:validator, e.g. and , and of coz, when the page run into error, this validator and callout will display to the user. e.g. When the user didn't fill in anything and submit the form, the ValidatorCalloutExtender will display a ballon and tell the user. Imagine one of this ballon/validatorCalloutExtender come out and on top of your screen at the moment.
Then you click the btnSelectUser (asp:button) to show the javascript modal dialog, and in the dialog, you Add some users, and once you hit the SELECT button inside this modal dialog, a MS AJAX web service is trigger as mentioned above, and once this web service is complete, it eval() the asp:hidden field's value (i.e. __doPostback(...))......and do the postback manually.
However, because of the validatorCalloutExtender ballon has display, it somehow cannot trigger the postback in this way, but when I close the ballon/validatorCalloutExtender, the manual postback using eval() is just working fine. Even more strange is that, when the ballon is displayed, the first time I click the SELECT button inside this modal dialog it doesn't fire the postback, however, if I do the same thing again (i.e. open up the javascript dialog, and choose some users, then click the SELECT button again). It able to do the manual postback....and I don't understand why the first time doesn't work.
This has really drive me crazy, hope anyone here can help, would be really appreciate. Thank you so much folks. :)
Have a nice day. Looking to heard from you all shortly.
When you call __doPostBack(eventTarget, eventArgument) a form submission is triggered:
This from post will proceed if WebForm_OnSubmit(); return true.
WebForm_OnSubmit result depends on ValidatorOnSubmit result, which in turn depends on
ValidatorCommonOnSubmit result if Page_ValidationActive == true.
Now if you are still with me, as in the function below:
function ValidatorCommonOnSubmit() {
Page_InvalidControlToBeFocused = null;
var result = !Page_BlockSubmit;
if ((typeof(window.event) != "undefined") && (window.event != null)) {
window.event.returnValue = result;
}
Page_BlockSubmit = false;
return result;
}
The result of ValidatorCommonOnSubmit depends on Page_BlockSubmit, so the only thing to block your postback is Page_BlockSubmit == true, it has nothing to do with validation callouts.
I was unable to simulate your case, but if you could post a full code sample it will help me track down the issue.