Text Box Values got lost in ASP.NET page load Event - asp.net

currently i was working in asp.net web application .
In asp page i was assign values to all controls on page load event using the Query string value.
On Compiling with break point i was able to see the values in the text box and other controls.But after completing the Page load event all my assigned values for the text boxes *got lost.*
Help me to solve this issue

in ASP page
<input type="hidden" id="hidtext" runat="server" value="">
in JScript
<script>
document.getElementById("hidtext").value = document.getElementById("textbox1")
.value;
</script>
after post back
textbox1.text=hidtext.value;

Related

can I run multiple server side forms in asp .net

In my project I want to run 2 forms in one webpage which is master page one is for contact us and one is for signup user. but multiple server side forms are not allowed. is there any solution for fix it?
You can use postback ability of Asp.net Webforms.
You should create one button for singup and another one for contact. You can catch event in server side and you do what want to do.
You can create regular client side forms created using HTML in the master page, and use the Request.Form to read the posted data. For this to work, all the input elements must have a name, and you can read them using Request.Form["ElementName"].
Take into account that forms cannot be nested.
So, your master page needs to llok like this
...
<body>
<form id="form1" runat="server">
</form>
<form id="contact" action="Contact.aspx" method="post">
<input type="text" name="Message"/>
<input type="submit" value="Contact us!"/>
</form>
</body>
The first <form> is the regular ASP.NET server side form, which supports server side components
The second <form> is a custom HTML form. It doesn't have the runat="server" attribute, and it's outside the server side <form>.
The second form action points to a .aspx page. In its page load event you can use the Request.Form["Name"] to acces the name of the contact form. Note that you also need to include a submit button to send the data to the server, and a method="post" to specify the method to send the page.
This is resorting to "basic" HTML controls, so there is no View State, and the posted values will be lost if they're not reset in the server. I.e. if the form is posted, and there's an error, the previously posted values will be lost when rendering the page again.
If you want to make it more sophisticated you can use Javascript and, optionally AJAX. But that's a more complex solution. See this for an example.
ASP.NET Forms only supports one form. You could use an iFrame and render your second page (second form) inside of the iFrame.
Here is an interesting post about placing some page content after the tag. This may be helpful to you.
http://forums.asp.net/t/1611822.aspx?Dynamically+adding+content+to+page+outside+of+the+aspnet+form+from+within+a+UC

using classic asp code inside asp.net?

I have a application that running both classic asp and asp net. inside the classic asp page, I have a combo box and depends on the selection of the combo box I need to do something inside my asp.net page. For instance, if inside my classic asp page, I have a combo box and inside the combo box; book is selected than when I enter a price for book as a zero inside my asp.net page I supposed to get an alert. Is there any way to do that?
asp.net code
if (Convert.ToDecimal(Values["myBookPrice"]) == 0)
{
//You cannot use 0 price for books!
}
Let say that you have some input control on any page, html, asp what ever, with some parametre that you wish to pass to an asp.net page
if the input control have a name attribute like
<form method="post" action="thenewpage.aspx">
<input name="nameOfInput" type="text" id="idofinput" />
<input type="submit" name="btnGo" value="Create Box" id="btnGo" />
</form>
and you have a button that make post back to an asp.net page, then you get that parametre on asp.net side using the Request.Form and the name of the input control as:
Request.Form["nameOfInput"]
If you make a call the page with url parameter, you need to use some kind of javascript to dynamically create the URL string for the call.
The issue that you have here, is that the asp.net page will hit the validation of the page security because is not going to find the page validation informations he needed to secure the page.

userControl repeated with Form tag disappearing

I have a Contact userControl that have "save contact" as submit button and fields inside form tag we repeat this userControl with Code 20 times in one page
My problem is the Form Tag in the first userControl is hiding somehow --- i checked the userControl with developer Tool IE9 , firebug Firefox7 and the Form is not appearing in the first userControl and its appearing with the rest 19 Controls
I tried to View Source and take html copy in new html file in VS -- i found form is exist
i dont know if iam clear enough but please advice if you need more info
If you're running a form tag at the server, inside a user control, and then displaying this user control more than once on the page, then you will have multiple form tags running at server on one page, which is not allowed by ASP.NET
Take the form tag outside of the user control like:
<form runat="server">
<uc:Contact />
<uc:Contact />
<uc:Contact />
</form>

ASP.Net PostBack & Button Internal

i worked for long time with windows apps using .net. for last 2 year i am working with asp.net. we often work with asp.net button control. when we click on button then postback occur and right server side event called by asp.net engine. i how link & image button causes postback when user click on those button.
when we work with link & image button then __doPostback js function is called and that causes form submit to server and request the same page and asp.net engine detect which control causes the postback from the hidden input control called eventTarget and invoke right event handler for that control.
but i dont know when we work with asp.net button control like
<asp:Button ID="SampleButton" runat="server"
Text="Submit"
OnClick="ButtonClick" />
when we click button then also form submit but how. i know that in this case __doPostback does not invoke because for button __doPostback is never rendered in the page. so in this case form submit but how asp.net engine detect which button causes postback and invoke right event handler?
how we get the data from textbox like txt1.text when postback occur. is it extracted from viewstate....am i right.
please answer for my 2 question. try to explain here instead of giving any url...thanks.
It's pretty simple with respect to how controls postback. They do it in the same fashion as pure html solutions. There is a Form tag on the page. When the button is pressed it causes the form to submit a postback to the server.
Notice the action target of the form tag, it points to my aspx page
This is all generated by the aspx page itself.
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRk5H5eaMNZp5tsD/GQ2iYj2p8J0as=" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKmxpCiBgKSotaIC5iWtiHNi+oxYiuBULPgr5d0/WFu" />
</div>
<div>
<input type="submit" name="btn1" value="click me" id="btn1" />
</div>
</form>
Yes asp:button works differently by default. It outputs a standard HTML Submit button which posts back to the Action URL specified on the form. It therefore doesn't use events in the same way as other controls.
However if you add a OnCommand and assign CommandName/CommandArgs to the control, it will then cause the same event based callback behaviour as other controls. The same is true of OnClick. I assumed this used the same process as other controls but actually it's different.
It looks like it uses __VIEWSTATE and __EVENTVALIDATION to determine which form posted back, and the name of the submit button id is posted in the form as part of part of standard HTML form behaviuor. This is what is used to trigger the server-side events.

Asp.net dynamic controls from l2e

G'day, I have an aspx page that has its html stored in a sql server 2008 table which uses linq to entities to retrieve & display in a placeholder on the page. This all displays correctly except for an asp button that will not display. Viewing the source of the page shows that the button is there but it is not on the page.
Page = Page.Replace("!LOGINBUTTON!", "< asp:Button id='login' text='Login' runat='server' />")
How do I get it to display?
Thanks.
Whatever code you are replacing with !LOGINBUTTON! is .ASPX code. It is not a pure HTML to display button.
When ASP.net actually render page asp:Button Converted with HTML <Input Type="Button" ..... with appropriate Javascript functions(for postback).
In this case if you want to see button with its postback event you need to write
Page = Page.Replace("!LOGINBUTTON!", "< intput type='Button' id='login' text='Login'/>")
I hope it will work.

Resources