I've created FormView let user enter the data to save into database. And i need to disable one of the textbox and automatic set the GUID to the textbox. how can i do that?
<InsertItemTemplate>
RouteGUID:
<asp:TextBox ID="RouteGUIDTextBox" runat="server"
Text='<%# Bind("RouteGUID") %>' Enabled="False" />
<br />
you should Bind the FormView control on Page_Load..or should call the Formview.DataBind() method on page_load...as i can't see your full code, so said this as an assumption.
Related
I am using ASP.NET and C# couple text boxes to calculate results entered. Textbox2 has a value entered and on button click Textbox1 gets populated. This works fine the first time I enter the value. But the second time I change the value in Textbox2, I see that the value is being assigned to Textbox1 while debugging on Button click, but doesn't show up on the screen. I have many other controls and a master page. The textboxes are within an update panel.
Can someone help me what's going on?
Here is the code:
<asp:TextBox ID="Textbox1" runat="server" Width="150px" TabIndex="6" MaxLength="8"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="Textbox2" Width="150px" Visible="false"></asp:TextBox> 
<asp:ImageButton runat="server" ID="imgCalcAdjRate" ImageUrl="~/Resource/Images/calrate_0.bmp" onmouseout="this.src='../Resource/Images/calrate_0.bmp'" onmouseover="this.src='../Resource/Images/calrate_1.bmp'" Height="25px" Width="25px" Visible="false" onclick="imgCalcAdjRate_Click" />
Check the postback in the page_load function.
if(!Page.IsPostBack) {
}
I think you are loosing information on post back. The data is changed, but it get reset on post back.
I am using ASP.NET and C# couple text boxes to calculate results entered. Textbox2 has a value entered and on button click Textbox1 gets populated. This works fine the first time I enter the value. But the second time I change the value in Textbox2, I see that the value is being assigned to Textbox1 while debugging on Button click, but doesn't show up on the screen. I have many other controls and a master page. The textboxes are within an update panel.
Can someone help me what's going on?
Here is the code:
<asp:TextBox ID="Textbox1" runat="server" Width="150px" TabIndex="6" MaxLength="8"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="TextBox1" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="Textbox2" Width="150px" Visible="false"></asp:TextBox> 
<asp:ImageButton runat="server" ID="imgCalcAdjRate" ImageUrl="~/Resource/Images/calrate_0.bmp" onmouseout="this.src='../Resource/Images/calrate_0.bmp'" onmouseover="this.src='../Resource/Images/calrate_1.bmp'" Height="25px" Width="25px" Visible="false" onclick="imgCalcAdjRate_Click" />
Check the postback in the page_load function.
if(!Page.IsPostBack) {
}
I think you are loosing information on post back. The data is changed, but it get reset on post back.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Height="146px"
Width="308px">
<Columns>
<asp:TemplateField HeaderText="Original Price" ControlStyle-Width="100px">
<ItemTemplate>
<asp:TextBox ID="txtOriginalPrice" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfv" runat="server" ControlToValidate="txtOriginalPrice"
ValidationGroup="GridView1" Display="Static" ErrorMessage="" Text="*"></asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am using above code but its not working though I have put requirefield validator it does not show me the '*'
Yes, your requiredfieldvalidator is certainly there, and it knows which control to validate.What is missing is "when to validate that control".And to answer this question you need to add your textbox the same ValidationGroup with your requiredfieldvalidator and also the control(this can be a button for example) causes to do a validation.So your code will be like
<%--<asp:Button ID="Button1" runat="server" ValidationGroup="GridView1" Text="Benjamin"...Somewhere in your code--%>
<asp:TextBox ID="txtOriginalPrice" runat="server" ValidationGroup="GridView1"></asp:TextBox>
So don't forget these question
What to validate?(a textbox)
When to validate?(after a button click)
After what action try to validate?(a button click)
With what to validate?(a requiredfieldvalidator)
All of these controls must have the same ValidationGroup.
In case you need the validation to be performed then check for something like this
<asp:Button ID="btnAdd" runat='server' ValidationGroup='GridView1' CausesValidation='true'.....
So now when you click the add button it will validate for those controls falling under the validation group you mentioned else the default value is "" hence you won't find any validation triggered.
Add ValidationGroup to TextBox (txtOriginalPrice), Button and other controls.
I want to use the gridview command button (edit) with the jquery not postback. Please help me.
Place an asp button in another item template and set its CommandName property to edit. This will work simillar to default edit button in grid view. Then you can call javascript function and perform your logic.
See the code below:
Remove the following line to avoid default edit button:
<asp:CommandField ShowEditButton="true" ShowCancelButton="true"/>
Add the following instead:
<asp:TemplateField HeaderText="headerName" >
<ItemTemplate>
<asp:Button ID="Button1" CommandName="edit" runat="server" Text="Button" />
</ItemTemplate>
</asp:TemplateField>
Hope this helps you..
I think you can do it in a gridview.What you need is to columns with textbox and display the data in the textbox and needs a button at the end .
<asp:TemplateField >
<HeaderTemplate>
Values
</HeaderTemplate>
<ItemTemplate>
<asp:textbox ID"txt" runat="server" cssclass="abc" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Spares">
<HeaderTemplate>
Edit column
</HeaderTemplate>
<ItemTemplate>
<asp:button id="abc" runat="server" text="save" cssclass="pqr" />
<input type="hidden" runat="server" value="" />
</ItemTemplate>
</asp:TemplateField>
Store the Id in a hidden field and it is possible to get the value of text box and hidden feild via jquery.
gridview will be rendered as html table and using parent() we can able to find the clicked row and after finding the row u can use find() to find the values in the txtbox and hidden feild. Use $ajax() or $post() to send data to server.
i have a webpage built in asp.net c#. it always a user to create a new record in a db table. there are there are two input fields, text and score. text cannot be a null value so if the user doesn't input text onsubmit, the page errors out. i want to throw in some simple error handling code in the code behind page. i've tried including an if/else on_inserted method but ran into some java script errors. any help would be apprieciated. thanks.
aspx page -----------------
<EditItemTemplate>
<customEditors:EditorWithCustomButtons_1 runat="server" ID="Editor1" Content='<%# Bind("userText") %>' />
</EditItemTemplate>
<InsertItemTemplate>
<customEditors:EditorWithCustomButtons_1 runat="server" ID="Editor1" Content='<%# Bind("userText") %>' />
</InsertItemTemplate>
why not use RequiredFieldValidator validator? it works inside the grid
<asp:RequiredFieldValidator id="RequiredFieldValidator2"
ControlToValidate="TextBox1"
Display="Static"
ErrorMessage="*"
runat="server"/>
Also don't forget to use page is valid before saving to the database.
if (page.isValid){
//send to db
}