Receive the session in list Box in separate rows - c#

hello m using visual studio 2012 , and trying to send session on different web page. its transferring my sessions but the problem is it is not showing in separate rows :( m using this code
Session["ProductName" + "\n"] += "\n" + ProductName; //this is on page 1
string pName = Convert.ToString(Session["ProductName" + "\n"]);
ListBox1.Items.Add("\n" + pName); //this one m using on targeted page

Use Environment.NewLine :
Session["ProductName" ] += Environment.NewLine + ProductName; //this is on page 1
Then you will not have to use "/n" in the other page Also.

Related

Adding blocks with jquery(append()) in asp.net mvc project

I have troubles with adding blocks with a specific attributes on my asp.net mvc project using jquery.
I need to add block into the page depending on what i have in a dropdownlist(created via c#)
I had created a hidden block in my view(view the code below) wich makes "select" tag with options from my "List"
<div id="other" class="EqItem">
<p>Else: #Html.DropDownList("else", Model.ModEq("",""))</p>
<p>Serial №: #Html.TextBox("serialelse")</p>
</div>
After loading the page i use a function which removes this block from DOM and makes the copy of html code of this block into a variable(blockToAdd )
function BlockDelete()
{
blockToAdd = $("#other").html();
$("#other").remove();
}
then i use this variable to dinamically add blocks into my page(the function below)
function ShowListEtc()
{
for (c = 0; c < 15; c++)
{
if (!$("#divotherlist" + c + "").length) {
id = "divotherlist" + c + "";
clas = "EqItem";
blockToAdd = blockToAdd.trim();
$(".rightside").append('<div id="' + id + '">' + blockToAdd
+ '<p><img id ="' + id + 'D"src="/Images/delete.png"
onclick="Delete(id)"></p></div>');
$("#" + id).attr('class', clas);
$("#"+id).show();
selectid = "othersel" + c;
$("#" + id).find("select").attr('id', selectid);
$('#' + selectid + ' option').each(function () {
this.setAttribute('id', TransL(this.text) + c);
this.setAttribute('onclick', 'MakeNameParent(id)')
});
break;
}
}
}
The point is that i try to change attributes within created block(append(') but they are not applying!
When i made the code first time, it worked, but suddenly it had stopped to work, then i tried to use .prepend instead of .append, it began to work for a while but after reopening the project, it had stopped to work again!
Please tell me what i've done incorrect!
Thank you!

How to send Request.Form

I'm doing something really bad with my code. I'm getting all data posted to the actual page and putting into html inputs:
private void GetPostedForm()
{
System.Text.StringBuilder displayValues = new System.Text.StringBuilder();
System.Collections.Specialized.NameValueCollection postedValues = Request.Form;
for (int i = 0; i < postedValues.AllKeys.Length; i++)
{
String nextKey = postedValues.AllKeys[i];
if (nextKey.Substring( 0, 2 ) != "__")
{
displayValues.Append( "<input type='hidden' name='" + nextKey + "' value='" + postedValues[i] + "'/>" );
}
}
hiddensPost.InnerHtml = displayValues.ToString();
}
But the html inputs in this page are useless to me. I'm putting a page between 2 older pages ("A" sent form to "B"). Now I need to send "A" to "X" and then send to "B".
The question is: How can I put the requested form into the actual form to send to the next page without doing all this mess in HTML?
You can put your steps(A,X,B) and it's visible inputs, into separate asp-panels(pnlA,pnlX,pnlB)
then simply toggle panels visibility in which state you want.the ViewState will do it for you (store controls states into one hidden field within the form to post again with inputs)
so you may post user entered data 3 times with one html form( the famous asp.net form)
another solution is here , the asp.net wizard control
If you can, just change the method to GET and pass the QueryString along from page to page.

WatIn Add a new option to a Selectlist?

I need to add a new option to a selectList in one of my unit tests, and I can't figure out how to do it.
The Dropdown currently has 2 options, I want to add a third, and use it.
I tried to use JavaScript injection using http://stevenharman.net/blog/archive/2007/07/10/add-option-elements-to-a-select-list-with-javascript.aspx as a base, but that failed. I get exceptions that crash the IE browser every time, and the text "RunScript failed" gets printed into my logs even though I don't use that text in my error output.
Is this possible in Watin? Or has Open Source Failed me?
Using the code in the link you provided, with one small change I've gotten it to work.
My changes
Changed the ID to the ID of my dropdown (of course!)
Changed the $ in the element get to 'document.getElementById'. With the $ in there instead I don't see any obvious errors or anything like that; just no action taken.
The 'New Option' is added to the dropdown as the last item and it is the selected item.
string js = "";
js = js + "var theSelectList = document.getElementById('myDropDownID'); ";
js = js + " AddSelectOption(theSelectList, \"My Option\", \"123\", true);";
js = js + " function AddSelectOption(selectObj, text, value, isSelected) ";
js = js + "{";
js = js + " if (selectObj != null && selectObj.options != null)";
js = js + "{";
js = js + " selectObj.options[selectObj.options.length] = new Option(text, value, false, isSelected);";
js = js + "}}";
myIE.Document.Eval(js);
My setup
WatiN 2.0
IE8
Win7
Checked when the dropdown has 1 entry and 2 entries; both scenarios had "My Option" added without issue.

AJAX Control Toolkit's combobox + IE are too slow

I have problems with optimizing AJAX Control Toolkit. The specific problem is that 4800 records take about 30 seconds to bind in Internet Explorer (only 2 seconds in Opera & Firefox). I've tried anything, but I still can't improve the load time in IE.
I've already enabled compression and caching, I'm using ToolkitScriptManager instead of ScriptManager. I've tried setting LoadScriptsBeforeUI and EnablePartialRendering to false, but it still doesn't help.
This is the query I use for binding.
var osoba =
from o in db.osobas
orderby o.osoba_prezime
select new {
o.osoba_id,
person = o.osoba_prezime + " " +
o.osoba_ime + " | " +
o.tijelo.tijelo_naziv + " | " +
o.radno_mjesto.rm_naziv_m
};
cb1.DataSource = osoba;
cb1.DataTextField = "person";
cb1.DataValueField = "osoba_id";
cb1.DataBind();
cb1.Items.Insert(0, " ");
Any help would be appreciated. Thank you!
Do you happen to have the developer toolbar open? I've had speed issues in IE when the toolbar is running, and when it's closed, load times are considerably faster.

Creating a customized "Yes / No" alert box in asp.net (javascript) - Part 2

I am trying to create a customized messagebox using javascript but not getting too far.
string txtConfirmMessage = "On " + DateTime.Now + ", ";
txtConfirmMessage = txtConfirmMessage + sUserID;
txtConfirmMessage = txtConfirmMessage + " added this record. Do you want to continue? ";
btnSubmit.OnClientClick = #"return confirm('" + txtConfirmMessage + "' Do you want to continue);";
I need to display a custom message involving the UserID, the date, and the value that the user has enetered. When I click the Submit button, the messagebox does not pop up.
Update:
I know this code is executed at the Page_Load event. However, is it possible to display in this alert box, a value that the user has selected (that action occurs after the page load event) ?
Any ideas to resolve this issue?
The javascript that you have is not valid, as the "confirm" method taks a single parameter, but you are giving it two bits.
Try this modified version.
string messageFormat = "On {0}, {1} added this record. Do you want to continue?";
string formattedMessage = string.format(messageFormat, DateTime.Now, sUserID);
btnSubmit.OnClientClick = "return confirm('" + formattedMessage + "');";
You just have an extra string after the one you're passing to confirm(), change it to this:
btnSubmit.OnClientClick = #"return confirm('" + txtConfirmMessage + "');";
About the update of the question, you could assign an OnClientClick event handler to the button as late as PreRender and the value will be persisted in the ViewState.

Categories